简体   繁体   English

在wordpress上设置类别页面中的自定义帖子数

[英]On wordpress set a custom number of posts in a category page

I have a wordpress website and in the custom template for the category 10 I have this code: 我有一个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; ?>

This returns the last five posts in my category. 这将返回我类别中的最后五个帖子。 But I do not want to lose the older posts. 但是我不想失去以前的职位。 I want to have two buttons newer posts||older posts at the bottom in order to let the user see all the posts. 我想在底部有两个按钮,较新的帖子||较旧的帖子,以便让用户看到所有帖子。

What I've tried: setting the max number in settings-> reading and to use this code in functions.php (with no results): 我试过的:在settings->读取中设置最大数量,并在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');

Thanks! 谢谢!

< when u click on new posts/older posts button get the page number(which is stored inside $paged varible) pass this inside the arguments <当您单击新帖子/旧帖子按钮时,获取页码(存储在$ 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;
            }

       }
   ?>

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM