我想建立一个wordpress blog. 我有一个带有特色帖子的循环,它来自“特色”类别,并显示一个突出帖子的滑块。
在这下面,我有定期的帖子。常规提要效果很好,但特色帖子只显示来自底部循环所在位置的帖子。例如,如果我在主提要的第一页上,则顶部滑块将仅显示同样在第一页上的具有特色类别的帖子。
如何使我的滑块循环从所有特色类别帖子中拉出?
编辑:添加代码,如下所示:
<?php
/** Homepage file */
get_header(); ?>
<div id="rotator-wrapper">
<div class="featured-rotator">
<?php if ( have_posts() ): ?><ul>
<?php while ( have_posts() ) : the_post(); ?>
<?php if ( in_category(\'featured\') ): ?>
<li class="post">
<div class="image"><?php the_post_thumbnail(); ?></div>
<h2><a href="<?php esc_url( the_permalink() ); ?>" title="Permalink to <?php the_title(); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<?php if (get_post_meta($post->ID, "Author", true)): ?>
<span class="author">By <?php echo get_post_meta($post->ID, "Author", true); ?></span>
<?php endif; ?>
<?php the_content(__("Continue reading »")); ?>
</li>
<?php endif; ?>
<?php endwhile; ?>
</ul><?php endif; ?>
</div>
</div>
<div id="content-wrapper">
<h2 class="recent">Recent Reviews</h2>
<?php if ( have_posts() ): ?>
<ol>
<?php while ( have_posts() ) : the_post(); ?>
<li class="post">
<article class="post-excerpt">
<div class="image"><?php the_post_thumbnail(); ?></div>
<div class="post-meta">
<h2 class="post-title"><a href="<?php esc_url( the_permalink() ); ?>" title="Permalink to <?php the_title(); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<?php if (get_post_meta($post->ID, "Author", true)): ?>
<span class="author">By <?php echo get_post_meta($post->ID, "Author", true); ?></span>
<?php endif; ?>
</div><!--post-meta-->
<?php the_content(__("Continue reading »")); ?>
</article>
</li>
<?php endwhile; ?>
</ol>
<nav class="oldernewer cf">
<div class="newer"><?php previous_posts_link(\'Newer Entries »\') ?></div><!--.newer-->
<div class="older"><?php next_posts_link(\'« Older Entries \') ?></div><!--.older-->
</nav><!--.oldernewer-->
<?php else: ?>
<h2>No posts to display</h2>
<?php endif; ?>
</div>
<?php get_footer(); ?>
最合适的回答,由SO网友:TomHarrigan 整理而成
为滑块立柱创建新的WP\\U查询。
<div class="featured-rotator">
<?php $slide_query = new WP_Query( \'category_name=featured\' );
if ( $slide_query->have_posts() ): ?><ul>
<?php while ( $slide_query->have_posts() ) : $slide_query->the_post(); ?>
<li class="post">
<div class="image"><?php the_post_thumbnail(); ?></div>
<h2><a href="<?php esc_url( the_permalink() ); ?>" title="Permalink to <?php the_title(); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<?php if (get_post_meta($post->ID, "Author", true)): ?>
<span class="author">By <?php echo get_post_meta($post->ID, "Author", true); ?></span>
<?php endif; ?>
<?php the_content(__("Continue reading »")); ?>
</li>
<?php endwhile; ?>
</ul><?php endif; wp_reset_postdata(); ?>
</div>