admin管理员组文章数量:1026989
I've created a custom category.php
for my client. The issue is, that if I click to next/prev pagination links, it shows the same posts. Any idea what can be wrong?
category.php
<?php
/* Category template file */
get_header();
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$the_query = new WP_Query( 'posts_per_page=2&paged=' . $paged );
?>
<div id="content">
<img id="eu-logo" src="<?php bloginfo('template_url')?>/img/title.png" />
<div class="article">
<?php global $post;
$args = array('category' => 11, 'posts_per_page' => 2, 'order_by' => 'date');
$custom_posts = get_posts($args);
foreach($custom_posts as $post) : setup_postdata($post);
echo "<div class='post'><h2 class='article__title'><a href='";
the_permalink();
echo "'>";
the_title();
echo "</a></h2>";
the_excerpt();
echo "</div>";
endforeach;
echo "<div id='forum-link'>";
echo "<a class='custom-nav' href=''>Main Page</a><br />";
echo "<a class='custom-nav' href='/'>Forum</a>";
echo "</div>";
?>
</div>
<div><?php next_posts_link('Next Page »') ?></div>
<div><?php previous_posts_link('« Previous Page') ?></div>
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>
I've created a custom category.php
for my client. The issue is, that if I click to next/prev pagination links, it shows the same posts. Any idea what can be wrong?
category.php
<?php
/* Category template file */
get_header();
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$the_query = new WP_Query( 'posts_per_page=2&paged=' . $paged );
?>
<div id="content">
<img id="eu-logo" src="<?php bloginfo('template_url')?>/img/title.png" />
<div class="article">
<?php global $post;
$args = array('category' => 11, 'posts_per_page' => 2, 'order_by' => 'date');
$custom_posts = get_posts($args);
foreach($custom_posts as $post) : setup_postdata($post);
echo "<div class='post'><h2 class='article__title'><a href='";
the_permalink();
echo "'>";
the_title();
echo "</a></h2>";
the_excerpt();
echo "</div>";
endforeach;
echo "<div id='forum-link'>";
echo "<a class='custom-nav' href='https://test'>Main Page</a><br />";
echo "<a class='custom-nav' href='https://test/forum/'>Forum</a>";
echo "</div>";
?>
</div>
<div><?php next_posts_link('Next Page »') ?></div>
<div><?php previous_posts_link('« Previous Page') ?></div>
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>
Share
Improve this question
asked Mar 21, 2019 at 12:05
Runtime TerrorRuntime Terror
1032 bronze badges
3
|
1 Answer
Reset to default 1This should be
$args = array('category' => 11, 'posts_per_page' => 2, 'order_by' => 'date');
like this
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array('category' => 11, 'posts_per_page' => 2, 'order_by' => 'date', 'paged' => $paged);
I've created a custom category.php
for my client. The issue is, that if I click to next/prev pagination links, it shows the same posts. Any idea what can be wrong?
category.php
<?php
/* Category template file */
get_header();
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$the_query = new WP_Query( 'posts_per_page=2&paged=' . $paged );
?>
<div id="content">
<img id="eu-logo" src="<?php bloginfo('template_url')?>/img/title.png" />
<div class="article">
<?php global $post;
$args = array('category' => 11, 'posts_per_page' => 2, 'order_by' => 'date');
$custom_posts = get_posts($args);
foreach($custom_posts as $post) : setup_postdata($post);
echo "<div class='post'><h2 class='article__title'><a href='";
the_permalink();
echo "'>";
the_title();
echo "</a></h2>";
the_excerpt();
echo "</div>";
endforeach;
echo "<div id='forum-link'>";
echo "<a class='custom-nav' href=''>Main Page</a><br />";
echo "<a class='custom-nav' href='/'>Forum</a>";
echo "</div>";
?>
</div>
<div><?php next_posts_link('Next Page »') ?></div>
<div><?php previous_posts_link('« Previous Page') ?></div>
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>
I've created a custom category.php
for my client. The issue is, that if I click to next/prev pagination links, it shows the same posts. Any idea what can be wrong?
category.php
<?php
/* Category template file */
get_header();
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$the_query = new WP_Query( 'posts_per_page=2&paged=' . $paged );
?>
<div id="content">
<img id="eu-logo" src="<?php bloginfo('template_url')?>/img/title.png" />
<div class="article">
<?php global $post;
$args = array('category' => 11, 'posts_per_page' => 2, 'order_by' => 'date');
$custom_posts = get_posts($args);
foreach($custom_posts as $post) : setup_postdata($post);
echo "<div class='post'><h2 class='article__title'><a href='";
the_permalink();
echo "'>";
the_title();
echo "</a></h2>";
the_excerpt();
echo "</div>";
endforeach;
echo "<div id='forum-link'>";
echo "<a class='custom-nav' href='https://test'>Main Page</a><br />";
echo "<a class='custom-nav' href='https://test/forum/'>Forum</a>";
echo "</div>";
?>
</div>
<div><?php next_posts_link('Next Page »') ?></div>
<div><?php previous_posts_link('« Previous Page') ?></div>
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>
Share
Improve this question
asked Mar 21, 2019 at 12:05
Runtime TerrorRuntime Terror
1032 bronze badges
3
-
You are missing
'paged'
element in$args = array('category' => 11, 'posts_per_page' => 2, 'order_by' => 'date');
– Qaisar Feroz Commented Mar 21, 2019 at 12:19 - And how should I add it? – Runtime Terror Commented Mar 21, 2019 at 12:21
- Please see my answer – Qaisar Feroz Commented Mar 21, 2019 at 12:26
1 Answer
Reset to default 1This should be
$args = array('category' => 11, 'posts_per_page' => 2, 'order_by' => 'date');
like this
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array('category' => 11, 'posts_per_page' => 2, 'order_by' => 'date', 'paged' => $paged);
本文标签: paginationCustom categoryphp paging shows the same posts
版权声明:本文标题:pagination - Custom category.php paging shows the same posts 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745668891a2162338.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
'paged'
element in$args = array('category' => 11, 'posts_per_page' => 2, 'order_by' => 'date');
– Qaisar Feroz Commented Mar 21, 2019 at 12:19