繁体   English   中英

wordpress:在静态首页上显示2个帖子+页面导航

[英]wordpress: display 2 posts on static frontpage + page navigation

我有一个静态的首页,上面有一些内容,并希望在静态内容的下方显示博客文章。

该循环应该始终只显示2个帖子,但是必须可以通过WP_PageNavi(我一直使用的插件)导航到较早的帖子。

我在首页做了一个静态页面,并在静态内容下面添加了WP_Query。 问题是,它不起作用,因为它仅显示最新的两个帖子。

看起来像这样:

<!-- here goes the static content stuff -->

<?php if(is_front_page()) { ?>  

<div class="news">
    <ul>
    <?php $my_query = new WP_Query(array('post_status' => 'publish', 'post__not_in' => $current_id));
        while ($my_query->have_posts()) : $my_query->the_post(); ?>

        <li class="news-post">
            <h2><?php the_title(); ?></h2>
            <p><?php the_content(); ?></a></p>
        </li>
        <?php endwhile; ?>
    </ul>

    <?php if(function_exists('wp_pagenavi')) { ?>
        <?php wp_pagenavi( array( 'query' => $my_query ) ); ?>
    <?php } ?>

忠告不胜感激

 <?php if(is_front_page()) { ?>  
    <div class="news">
        <ul>
            <?php 
                 $paged = (get_query_var('page')) ? get_query_var('page') : 1;

                $my_query = new WP_Query('post_type=post&post_status=publish&posts_per_page=2&paged=' . $paged);


                while ($my_query->have_posts()) : $my_query->the_post(); ?>

                <li class="news-post">
                    <h2><?php the_title(); ?></h2>
                    <p><?php the_content(); ?></a></p>
                </li>
            <?php endwhile; ?>
         </ul>

        <?php 
            if(function_exists('wp_pagenavi')):
                 wp_pagenavi( array( 'query' =>$my_query));
               endif; 
        ?>
    </div>
<?php } ?>  

在此处输入图片说明

暂无
暂无

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

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