Php 可湿性粉剂分页不循环通过职位
我正在尝试在其他人创建的WP Pro Real Estate 3的顶部设置一个儿童主题。在主题的其他地方,出现了不同的内容导航。我曾尝试连接一个用于分页的插件,但它也不会在帖子中循环。URL会更新,但显示的10篇帖子总是相同的 这是页面的代码。我应该首先从哪里找出问题的原因Php 可湿性粉剂分页不循环通过职位,php,wordpress,pagination,Php,Wordpress,Pagination,我正在尝试在其他人创建的WP Pro Real Estate 3的顶部设置一个儿童主题。在主题的其他地方,出现了不同的内容导航。我曾尝试连接一个用于分页的插件,但它也不会在帖子中循环。URL会更新,但显示的10篇帖子总是相同的 这是页面的代码。我应该首先从哪里找出问题的原因 <?php global $ct_options; if($ct_options['ct_layout'] == 'left-sidebar') { ge
<?php global $ct_options;
if($ct_options['ct_layout'] == 'left-sidebar') {
get_sidebar();
} ?>
<section id="blog" class="ten columns marT20 left">
<h2> Blog </h2>
<?php query_posts( 'cat=-39' ); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class('left clear'); ?>>
<?php if ( has_post_thumbnail() ) {
the_post_thumbnail();
} ?>
<h2 class="entry-title marB18"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>
<br/>
<?php ct_read_more_link(); ?>
<!-- <a href="<?php the_permalink(); ?>" class="read-more" />Read More</a> -->
<?php wp_link_pages(array('before' => '<div class="pagination">' . __('Pages:', 'responsive'), 'after' => '</div>')); ?>
</article>
<?php endwhile; endif; ?>
<?php if (function_exists("pagination")) {
pagination($additional_loop->max_num_pages);
} ?>
</section>
<div class="sidebar six columns marT20 left">
<?php if (function_exists('dynamic_sidebar') && dynamic_sidebar('Sidebar Blog') ) :else: endif; ?>
<div id="sidebar-inner">
<aside class="widget widget_text left" id="about-nic-nav"><h4>About Nicaragua</h4>
<div class="textwidget">
<?php query_posts( 'cat=39' ); ?>
<ul>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; endif; ?>
</ul>
</div>
</aside>
<div class="clear"></div>
</div>
</div>
博客
鉴于它在循环之后被称为,我建议插件中的分页()函数只添加页码。它实际上并不设置分页查询
为此,您需要确保在查询中包含paged
参数
例如,要按日期顺序显示每页5篇已发布的文章,请在循环之前包含此-
$args = array(
'orderby' => 'date',
'order' => DESC,
'paged' => get_query_var('paged'),
'posts_per_page' => 5,
'post_type' => 'post',
'post_status' => 'publish'
);
query_posts($args);
有关更多信息,请查看的部分
此外,如果您不确定这是什么,请查看
其他信息
顺便说一句,我注意到在您的代码中,您使用了两次循环。在很多情况下,这是必要的,但是在这两种情况下,您的内容似乎是相同的,因此无需回忆query\u posts()
。相反,在循环的第一次运行结束时,调用wp\u reset\u query()
(始终使用该调用是一个好习惯),它将指针设置回循环的开始,并将节省您的时间,因为您不必再次查询数据库
但是,如果您确实需要循环来输出不同的帖子,那么您应该使用newwp\u Query()
(老实说,我建议始终使用它,而不是The\u Query()
,因为如果需要的话,使用挂钩更容易定制)。比如说-
$args = array(
'cat' => 10,
'post_status' => 'scheduled'
);
$scheduled_posts = new WP_Query($args);
if($scheduled_posts->have_posts()) : while($scheduled_posts->have_posts()) : $scheduled_posts->the_post();
?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h2><?php the_title(); ?> </h2>
<div><?php the_content(); ?></div>
</div>
<?php
endwhile;
endif;
wp_reset_query();
$args=array(
“猫”=>10,
“post_状态”=>“已计划”
);
$scheduled_posts=新的WP_查询($args);
如果($scheduled_posts->have_posts()):而($scheduled_posts->have_posts()):$scheduled_posts->the_post();
?>
谢谢你!我以前见过args块,但我一定是遗漏了一部分,使其无法工作。但现在它可以工作了!干杯