2011-09-09 4 views
0

현재 게시물/페이지와 동일한 태그를 사용하여 관련 게시물을 쿼리하려고하지만 이미 격자를 생성하는 데 사용중인 코드 형식 내에서 작동해야했습니다. 내가 좋아하는 그것을 통합하려고 할 때 유망한 보였지만, Wordpress Querying Related Posts by tagWordpress 검색어 관련 게시물

..

<?php 
$c = 1; //init counter 
$bpr = 3; //boxes per row 
$test = ""; 
$posttags = get_the_tags(); 
$test = ''; 
$sep = ''; 
if ($posttags) { 
    foreach($posttags as $tag) { 
     $test .= $sep . $tag->name; 
     $sep = ","; 
    } 
} 
query_posts('tag=' .$test . '&showposts=-1'); if(have_posts()) : while (have_posts()) : the_post(); ?> 

는 불행히도 생성 아무것도 :

<?php 
$c = 1; //init counter 
$bpr = 3; //boxes per row 
if(have_posts()) : while (have_posts()) : the_post(); ?> 
<div class="postgrid" id="post-<?php the_ID(); ?>"> 

<div class="postthumb"> 
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('grid-post-image'); ?></a><div class="borderthumb"></div><div class="posttitle"><h1><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1> 
    <p><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">Click for more</a></p></div> 
    </div> 
</div> 

<?php 
if($c == $bpr) : 
?> 
<?php 
$c = 0; 
endif; 
?> 
<?php 
     $c++; 
    endwhile; 
endif; 
?> 

나는이 결과가 없습니다. 어떤 도움?

감사합니다. 나는 두 스크립트가 상충되고 있으며 나는 PHP가 없다고 생각한다. spec for query_posts에서

답변

0

:

당신은 차 목록을 만들 수 query_posts()를 사용하지 말아야 *

(예를 들어, 페이지 하단, 또는 사이드 바 위젯에 링크 목록에서 관련 게시물 목록). 대신, 당신은 WP_Query의 새로운 인스턴스를 만들거나 get_posts()를 사용해야합니다 *

get_posts()을 시도해보십시오.

$posts = get_posts('tag=' .$test); foreach($posts as $post){ setup_postdata($post); ?> 
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> 
<? } ?> 

당신은 $test 실제로 유효한 태그 또는 태그 설정되어 있는지 확인해야합니다.

+0

코드가 동적으로 페이지에 첨부 된 태그를 찾아 보여주기위한 방법이 있습니까? 따라서 테스트 페이지에 태그를 지정하면 테스트가 검색됩니다. 하지만 'test2'태그를 추가하면 test2가 발견됩니까? 이것이 내가 어쨌든하고 싶은 것 인 것처럼 궁금해하는 것입니다! – Amy

관련 문제