我正在编写一个循环,显示与特定WordPress标签相关的所有帖子。循环正常工作,并显示与特定标签相关的所有帖子。唯一的问题是,查询帖子不会限制要显示的帖子数量。有人可以帮忙吗?
非常感谢。
这是我的代码。
<div class="container">
<div class="bucket-top-row row">
<?php
// get all the tags from the database
$tags = get_tags();
foreach ($tags as $tag) {
$tag_id = $tag->term_id;
// create a custom wordpress query
// start the wordpress loop!
// echo "<h2>".$tag->name."- $tag_id</h2>";
query_posts("tag=$tag_id&post_per_page=12");
if (have_posts()) : while (have_posts()) : the_post();
?>
<div class="col-lg-4">
<div class="bucket-wrapper-standard-top-row">
<img class="image-bucket-standard"
src="<?php echo get_template_directory_uri() . '/images/blog-images/hero-img-1.jpg'; ?>" />
<h4 id="post-<?php the_ID(); ?>" class="bucket-text-standard">
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
<?php the_title(); ?></a></h4>
<p class="bucket-paragraph">
<?php the_excerpt();?>
</p>
<div class="author-text-bucket">
<div class="author-image six-sm">
<img class="author-img-post"
src="<?php echo get_template_directory_uri() . '/images/author-headshots/fitness-mark.png'; ?>" />
</div> <span class="author-name-post-bucket ">
<?php> the_author_posts_link(); ?></span>
<span class="bucket-category">
<?php> the_category(); ?></span>
<div class="lower-bucket-text">
<span class="author-job-title-bucket ">
<?php> the_author_nickname(); ?></span>
<span class="bucket-read-time">3min read</span>
</div>
<div class="underline-bucket"></div>
</div>
</div>
</div>
<?php endwhile; endif; // done our wordpress loop. Will start again for each category ?>
<?php } // done the foreach statement ?>
<!--
<div class="cta nav-previous alignleft">
<?php/* previous_posts_link( 'Older posts' );*/ ?>
</div>
<div class=" cta nav-next alignright">
<?php/* next_posts_link( 'Newer posts' ); */?>
</div> -->
</div>
</div>