我使用此代码加载带有自定义分类术语slug的相关帖子:
<?php
global $post;
$terms = get_the_terms( $post->ID , \'topics\', \'string\');
$do_not_duplicate[] = $post->ID;
if(!empty($terms)){
foreach ($terms as $term) {
query_posts( array(
\'topics\' => $term->slug,
\'showposts\' => 4,
\'caller_get_posts\' => 1,
\'post__not_in\' => $do_not_duplicate ) );
if(have_posts()){
while ( have_posts() ) : the_post(); $do_not_duplicate[] = $post->ID; ?>
但我总是得到4个以上的帖子。我如何才能真正将此查询设置为仅4篇帖子?
谢谢
公元
SO网友:ad2003
谢谢
这项工作:
<?php
global $post;
$terms = get_the_terms( $post->ID , \'topics\', \'string\');
$do_not_duplicate[] = $post->ID;
if(!empty($terms)){
foreach ($terms as $term) {
query_posts( array(
\'topics\' => $term->slug,
\'numberposts\' => 4,
\'posts_per_page\' => 4,
\'caller_get_posts\' => 1,
\'post__not_in\' => $do_not_duplicate ) );
if(have_posts()){
while ( have_posts() ) : the_post(); $do_not_duplicate[] = $post->ID; ?>