0

我有一个 wordpress 网站,在类别 10 的自定义模板中我有这个代码:

<?php
function new_excerpt_length($length) {return 30;} add_filter('excerpt_length', 'new_excerpt_length');
global $post;
$args = array( 'numberposts' => 5, 'category' => 10 );
$myposts = get_posts( $args );
foreach( $myposts as $post ) :  setup_postdata($post); ?>
echo get_the_post_thumbnail($post_id, $size)?></div><div id="eu_post_category">
<h2><a class="roll-link" href="<?php the_permalink(); ?>"><span data-title="<?php the_title(); ?>"><?php the_title(); ?></span></a></h2>
<h6><?php the_excerpt(); ?></h6> 
<?php endforeach; ?>

这将返回我类别中的最后五个帖子。但我不想丢失旧帖子。我想在底部有两个按钮较新的帖子||较旧的帖子,以便让用户看到所有帖子。

我尝试过的:在设置中设置最大数量->阅读并在functions.php中使用此代码(没有结果):

function limit_posts_per_archive_page() {
if ( is_category('10') )
set_query_var('posts_per_archive_page', 5); // or use variable key: posts_per_page
}
add_filter('pre_get_posts', 'limit_posts_per_archive_page');

谢谢!

4

1 回答 1

0

<当你点击新帖子/旧帖子按钮时,获取页码(存储在 $paged 变量中)在参数中传递这个

     <?php
        $args = array(
            'paged'            => $paged,
            'category'        => 10,
            'posts_per_page'  => 5,
            'post_status'     => 'publish');
        query_posts($args);
        if ( have_posts() ) {
            while ( have_posts() ) { the_post();
                echo $post->post_title;
            }

       }
   ?>

供参考: http: //codex.wordpress.org/Function_Reference/query_posts http://codex.wordpress.org/Template_Tags/get_posts

于 2013-10-06T08:20:47.083 回答