首页 文章

在wordpress中只显示5个帖子

提问于
浏览
0

我已编辑并制作响应主题的模板页面,以制作帖子的功能图片的缩略图 . 好吧我可以看到它们,但即使帖子是9我只能看到5.如果我添加一个ony我看到新的,有一些像“只显示最新的5个帖子”但我无法理解WHERE !

get_header(); ?>
<?php if (have_posts()) : ?>

    <?php while (have_posts()) : the_post(); ?>

    <?php get_template_part( 'loop-header' ); ?>

        <?php responsive_entry_before(); ?>
        <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>       
            <?php responsive_entry_top(); ?>

            <?php get_template_part( 'post-meta-page' ); ?>



            <div class="post-entry">
                <?php the_content(__('Read more &#8250;', 'responsive')); ?>
                <?php wp_link_pages(array('before' => '<div class="pagination">' . __('Pages:', 'responsive'), 'after' => '</div>')); ?>
            </div><!-- end of .post-entry -->

(this is my added code) 
                            <ul>
            <?php  
            $posts = get_posts();
                foreach($posts as $post) : setup_postdata($post);

                ?>
                <li><div class="fotoBoxContent"><a class="fotoBox" href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); the_title(); ?></a></div></li>
            <?php  endforeach; ?>
            </ul>

<?php responsive_entry_bottom(); ?>      
        </div><!-- end of #post-<?php the_ID(); ?> -->       
        <?php responsive_entry_after(); ?>

        <?php responsive_comments_before(); ?>
        <?php comments_template( '', true ); ?>
        <?php responsive_comments_after(); ?>

    <?php 
    endwhile; 

    get_template_part( 'loop-nav' ); 

else : 

    get_template_part( 'loop-no-posts' ); 

endif; 
?>

2 回答

  • 0

    尝试在 <?php while (have_posts()) : the_post(); ?> 之前立即添加 query_posts( 'posts_per_page=NUMBER_GOES_HERE' );

    NUMBER_GOES_HERE 替换为您想要显示的帖子数量 . 使用 -1 显示所有帖子

    也在Wordpress本身内设置 - >阅读有一个字段,您可以在其中设置 Blog pages show at most

  • 0

    我仍然不确定你想要实现什么,但如果你只想拥有主循环中帖子的缩略图,那么你不需要做额外的查询 .

    你需要做的就是这样:

    1.)在 <?php if (have_posts()) : ?> 之前,你初始化一些变量:

    $thumb_data='';
    

    2.) <?php if (have_posts()) : ?> 之后

    $thumb_data='<ul>';
    

    3.)用这个替换你的“添加代码”:

    $thumb_data.='<li><div class="fotoBoxContent"><a class="fotoBox" href="'.get_the_permalink().'">'.get_the_post_thumbnail()." ".get_the_title().'</a></div></li>';
    

    4.)在主while循环之后,添加:

    $thumb_data='</ul>';
    

    5.)Mow缩略图列表的所有HTML代码都在 $thumb_data 中,所以只需在希望HTML代码出现的模板中回显此变量 .

相关问题