Pagination shows Same posts

时间:2015-09-15 作者:Steve

我制作了一个自定义模板,我想在此模板中显示来自特定类别的所有帖子,不包括一些帖子,我按照需要获取,但分页显示相同的帖子,无论我是在第一页还是第二页,此模板是否有任何问题

任何帮助都将不胜感激

`

<?php /* Template Name: Blog Template */ ?>
<?php get_header(); ?>

<?php 
$homepageLayout = get_theme_mod(\'homepageLayout\', \'no-sidebar\');

?>

<div class="container pm-containerPadding-top-110 pm-containerPadding-bottom-90">
    <div class="row">

        <?php if($homepageLayout === \'no-sidebar\') { ?>

            <div class="col-lg-12 col-md-12 col-sm-12">




                <?php
$query = new WP_Query(\'cat=106,93,138,136,86,23,103,83,84,92,78,137\');


 if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); ?>

                    <?php get_template_part( \'content\', \'post\' ); ?>

                <?php }//end of posts ?>

                <?php } else { ?>
                     <p><?php _e(\'No posts were found.\', \'medicallinktheme\'); ?></p>
                <?php endif; ?> 

                <?php get_template_part( \'content\', \'pagination\' ); ?>

            </div>

        <?php } else if($homepageLayout === \'right-sidebar\') {?>

            <!-- Retrive right sidebar post template -->
            <div class="col-lg-8 col-md-8 col-sm-12">

                <?php
$query = new WP_Query(\'cat=106,93,138,136,86,23,103,83,84,92,78,137\');



 if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); ?>

                    <?php get_template_part( \'content\', \'post\' ); ?>

                <?php }//end of posts ?>

                <?php } else { ?>
                     <p><?php _e(\'No posts were found.\', \'medicallinktheme\'); ?></p>
                <?php endif; ?>  

                <?php get_template_part( \'content\', \'pagination\' ); ?>

            </div>

             <!-- Right Sidebar -->
             <?php get_sidebar(\'home\'); ?>
             <!-- /Right Sidebar -->

        <?php } else if($homepageLayout === \'left-sidebar\') { ?>

             <!-- Left Sidebar -->
             <?php get_sidebar(\'home\'); ?>
             <!-- /Left Sidebar -->

            <!-- Retrive right sidebar post template -->
            <div class="col-lg-8 col-md-8 col-sm-12">

                <?php
$query = new WP_Query(\'cat=106,93,138,136,86,23,103,83,84,92,78,137\');



 if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); ?>

                    <?php get_template_part( \'content\', \'post\' ); ?>

                <?php }//end of posts ?>

                <?php } else { ?>
                     <p><?php _e(\'No posts were found.\', \'medicallinktheme\'); ?></p>
                <?php endif; ?> 

                <?php get_template_part( \'content\', \'pagination\' ); ?>

            </div>

        <?php } else {//default full width layout ?>

            <div class="col-lg-12 col-md-12 col-sm-12">

<?php

$query = new WP_Query(\'cat=106,93,138,136,86,23,103,83,84,92,78,137\');



 if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); ?>

                    <?php get_template_part( \'content\', \'post\' ); ?>

                <?php }//end of posts ?>

                <?php } else { ?>
                     <p><?php _e(\'No posts were found.\', \'medicallinktheme\'); ?></p>
                <?php } ?> 

                <?php get_template_part( \'content\', \'pagination\' ); ?>

            </div>

        <?php }  ?>

    </div> <!-- /row -->
</div> <!-- /container -->
<?php get_footer(); ?>
`

1 个回复
SO网友:Steve

这就成功了。感谢米洛的链接

<?php 

$args = array(
    \'posts_per_page\' => 12,
    \'post_type\'      => \'post\',
    \'paged\'          => get_query_var( \'paged\' ),
    \'cat\'            => \'106,93,138,136,86,23,103,83,84,92,78,137\' 
);

$query = new WP_Query($args);

?>

相关推荐

无法在模板函数.php中使用IS_HOME

我试图在标题中加载一个滑块,但只在主页上加载。如果有帮助的话,我正在使用Ultralight模板。我正在尝试(在template functions.php中)执行以下操作:<?php if ( is_page( \'home\' ) ) : ?> dynamic_sidebar( \'Homepage Widget\' ); <?php endif; ?> 但这行不通。现在,通过快速的google,我似乎需要将请