TAG的Wordpress相关帖子(自定义查询)

时间:2014-08-23 19:40:20

标签: php wordpress

:)

所以,我正在尝试创建一个"相关帖子"目前正在阅读使用帖子TAGS的内容。我的主题 - 定制设计 - 有相关的帖子,但基于CATEGORY。

我尝试将其更改为标记,但绝对没有成功(只是一个空白的屏幕。; D) 你能帮帮我吗? :)

query_posts("post_type=any&cat=13&posts_per_page=8"); 
global $wp_query;
$totalposts = $wp_query->found_posts;
$i = 1; 

if (have_posts()): 
while (have_posts()): 
the_post(); 
include (TEMPLATEPATH . '/inc/categorias.php');

$thumb_image = wp_get_attachment_url(get_post_thumbnail_id($post->ID, 'full'));
$class_name = (empty($thumb_image))?("empty_image"):("");
$bigpost = ($i % 9 == 0)?"big-post $catURL":"$catURL";

$terms = get_terms( 'notepad', array(
'orderby'    => 'count',
'hide_empty' => 0
));

1 个答案:

答案 0 :(得分:0)

好的,我做到了。 :)

$tags = wp_get_post_tags($post->ID);
if ($tags) {
$first_tag = $tags[0]->term_id;
$args=array(
'tag__in' => array($first_tag),
'post__not_in' => array($post->ID),
'posts_per_page'=>8,
'caller_get_posts'=>1
);
$my_query = new WP_Query($args);
$totalposts = $wp_query->found_posts;
$i = 1;
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); 

include (TEMPLATEPATH . '/inc/categorias.php');

$thumb_image = wp_get_attachment_url(get_post_thumbnail_id($post->ID, 'full'));
$class_name = (empty($thumb_image))?("empty_image"):("");
$bigpost = ($i % 9 == 0)?"big-post $catURL":"$catURL";

然后,循环之后......

$i++; 
endwhile;
}
wp_reset_query(); 
}