所以我正在编写一个 wordpress 循环,我希望我的循环调用最新的十五页(不使用任何帖子,这不是一个选项)然后我循环遍历 LI 标签和 Span 标签来填充缩略图.如果您感到困惑,请查看 xxlbreakcomp.com
我的循环有效,但它只调用我的主页信息。我想我要么需要编写第二个循环或输出,但我都完成了但都不起作用。我有点只需要朝正确的方向插入,但我是完全迷失了。
<footer class="footer" role="contentinfo">
<div id="inner-footer" class="wrap clearfix">
<div id="video-thumbs">
<ul id="selected">
<?php
$query_args = array (
'orderby' => 'date',
'order' => 'DESC',
'post_per_page' => 15,
'post_type' => 'page',
'post__in'=> array (4,7,8,9,15,16,17,18,19,20,21,22,23,24,25)
);
$query = new WP_Query($query_args);
if ( $query->have_posts() ) :
while ( $query->have_posts()) : $query->the_post();
wp_reset_postdata ();
?>
<li data-permalink="<?php the_permalink(); ?>" class="selected">
<span style= "background: url('<?php bloginfo('template_directory'); ?>/library/images/thumb_pic.png')"></span>
<span><?php the_title(); ?></span>
</li>
<?php
endwhile;
endif;
?>
<?php wp_reset_postdata (); // reset the query ?>
</ul>
</div>
最佳答案
您可能正在使用 while 循环中的 wp_reset_postdata
调用将 post
重置为默认帖子。尝试将其删除为类似的内容,
if ( $query->have_posts() ) :
while ( $query->have_posts()) : $query->the_post();
?>
<li data-permalink="<?php the_permalink(); ?>" class="selected">
<span style= "background: url('<?php bloginfo('template_directory'); ?>/library/images/thumb_pic.png')"></span>
<span><?php the_title(); ?></span>
</li>
<?php
endwhile;
endif;
循环后的最终 wp_reset_postdata
看起来没问题。
关于php - WP_Query 只是循环主页,而不是页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17778908/