2013-08-19 1 views
2

나는 single.php 내부, 동일한 태그를 가진 게시물의 목록을 표시하려면 다음 코드를 사용하고 있습니다 : 그러나wordpress tag related posts에 대한 "no posts found"를 표시하는 방법?

<?php 
if (is_single()) { 
    $tags = wp_get_post_tags($post->ID); 
    if ($tags) { 
    $first_tag = $tags[0]->term_id; 
echo 'first_tag' .$first_tag; 
$args=array(
    'tag__in' => array($first_tag), 
    'post__not_in' => array($post->ID), 
    'showposts'=>5 
); 
$my_query = new WP_Query($args); 
if($my_query->have_posts()) { 
    echo 'Related Posts'; 
    while ($my_query->have_posts()) : $my_query->the_post(); ?> 
    <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php  the_title_attribute(); ?>"><?php the_title(); ?></a></p> 
    <?php 
    endwhile; 
} //if ($my_query) 
    } //if ($tags) 
    wp_reset_query(); // Restore global post data stomped by the_post(). 
} //if (is_single()) 
?> 

, 내가이 때를 위해 "게시물을 찾을 수 없습니다"같은 것을 표시 할 것이 동일한 태그가있는 다른 게시물이 없습니다.

어떻게하면 좋을지 아이디어가 있습니까?

답변

0

그냥 경우 ($ myquery-> havePosts)

... 
    <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php  the_title_attribute(); ?>"><?php the_title(); ?></a></p> 
    <?php 
    endwhile; 
} //if ($my_query) 
else{ 
    echo "No Posts" //Look I am HERE 
} 
    } //if ($tags) 
환상적인
+0

에 다른 문을 추가, 치료처럼 일! 고맙습니다. –

관련 문제