【问题标题】:Call top posts in different divs调用不同 div 中的热门帖子
【发布时间】:2013-06-25 04:55:48
【问题描述】:

我想让我的最新帖子显示所有信息(标题、作者、缩略图和内容),但仅显示另一个 div 中第二个最近帖子的标题。这是我的代码。它正确呈现了 div,但第二个 div 中的“标题”仍然是最新帖子的“标题”。

                <div id="blog-pane">


        <div id="blog-post">

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



            <div id="post-title">

                <?php the_title(); ?>

            </div>

            <div id="post-author">

                <?php the_author(); ?>
                &nbsp;
                <?php the_date(); ?>
                &nbsp;
                <?php the_time(); ?>

            </div>

            <div id="post-image">

                <?php the_post_thumbnail(); ?>

            </div>

            <div id="post-text">

                <?php the_content(); ?>

            </div>      

        <?php endwhile; ?>
        <?php endif; ?>
        <?php rewind_posts(); ?>


        </div>


        <div id="post-link-1">

            <?php

                query_posts( 'p' );

                while ( have_posts() ) : the_post();

                the_title();

                endwhile;


                wp_reset_query();
                ?>
        </div>

    </div>

</div>

<?php get_footer(); ?>

【问题讨论】:

    标签: php wordpress tags posts


    【解决方案1】:

    你可以尝试引入一些跳过逻辑让它跳过第一篇文章,

    <div id="post-link-1">
    
                <?php
    
                    query_posts( 'p' );
                    $count = 0;
                    while ( have_posts() ) { 
    
                           if ($count++ == 0) {
                               the_post();
                               continue;
                           }
    
                    the_post();
    
                    the_title();
    
                    }
    
    
                    wp_reset_query();
                    ?>
            </div>
    

    【讨论】:

    • 显示第二个最新帖子的内容,后跟第三个最新帖子的标题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-09
    • 1970-01-01
    • 1970-01-01
    • 2016-12-24
    • 1970-01-01
    相关资源
    最近更新 更多