在wordpress中只显示5个帖子

问题描述 投票:0回答:2

我已编辑并制作响应主题的模板页面,以制作帖子的功能图片的缩略图。好吧我可以看到它们,但即使帖子是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; 
?>  

wordpress post thumbnails show
2个回答
0
投票

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

用您想要显示的帖子数量替换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代码出现的变量。

© www.soinside.com 2019 - 2024. All rights reserved.