2010-06-08 11 views
1

나는 custum 분류법을 기반으로 관련 게시물을 표시하려고합니다. 나는 wordpress.org에서 그런 종류의 작품을 찾았습니다. 그러나 원본 게시물은 여러 번 결과에 중복됩니다. (단어는 내가 사용하는 맞춤 분류법의 이름입니다) 무슨 일이 일어날 것인가는 단일 게시물이 표시되는 양에 따라 복제된다는 것입니다. 어떤 생각이 그 원인일까요?사용자 정의 분류 문제로 Wordpress 관련 게시물

코드 :

<?php 
//for in the loop, display all "content", regardless of post_type, 
//that have the same custom taxonomy (e.g. words) terms as the current post 
$backup = $post; // backup the current object 
$found_none = '<h2>No related posts found!</h2>'; 
$taxonomy = 'words';// e.g. post_tag, category, custom taxonomy 
$param_type = 'words'; // e.g. tag__in, category__in, but genre__in will NOT work 
$post_types = get_post_types(array('public' => true), 'names'); 
$tax_args=array('orderby' => 'none'); 
$tags = wp_get_post_terms($post->ID , $taxonomy, $tax_args); 
if ($tags) { 
    foreach ($tags as $tag) { 
    $args=array(
     "$param_type" => $tag->slug, 
     'post__not_in' => array($post->ID), 
     'post_type' => $post_types, 
     'showposts'=>5, 
     'caller_get_posts'=>1 
    ); 
    $my_query = null; 
    $my_query = new WP_Query($args); 
    if($my_query->have_posts()) { 
     while ($my_query->have_posts()) : $my_query->the_post(); ?> 
     <h3><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3> 
     <?php $found_none = ''; 
     endwhile; 
    } 
    } 
} 
if ($found_none) { 
echo $found_none; 
} 
$post = $backup; // copy it back 
wp_reset_query(); // to use the original query again 
?> 

답변

0

그것은 당신이 중복을 받고있는 foreach 루프 내부입니다. 이 코드는 효과적으로 말하고 있습니다.

  1. $param_type
  2. 용어를 들어,

그래서 당신은보다 더 많은 태그 된 게시물이있는 경우 해당 용어로 태그가 5 개 게시물을 얻을 분류 유형에 대한 모든 조건을 얻기 동일한 택 소노 미의 한 용어는 두 번 이상 나타날 것입니다.

쿼리 한 게시물을 post__not_in 어레이에 반복적으로 추가하여 다시 나타나지 않도록 할 수 있습니다.

  1. 그런 다음 post__not_in' => $post_not_in,와 라인 post__not_in' => array($post->ID),을 대체 단지 if ($tags) {

  2. $post_not_in = array($post->ID);를 추가합니다. 내가 정의 분류에 대한 this plugin를 사용하는 게시물 관련 나를 위해로서

  3. 마지막으로, $found_none = '';

+0

안녕하세요, DeadMedic, 답장을 보내 주셔서 감사합니다. 나는 조정을했지만, 불행히도 나는 여전히 중독자가된다. 실제로 코드 $ post_not_in = array ($ post-> ID)를 완전히 무시한 것 같습니다. 내가 그것을 넣든 안 넣든 상관 없습니다. 결과는 같습니다. 아마도 뭔가 간단한 오류 일 수도 있지만 그게 뭔지 알 수는 없습니다 .. – Nordin

+0

어떤 WordPress 버전을 사용하고 있습니까? – TheDeadMedic

+0

2.9.2와 협력 중입니다. – Nordin

0

후, 당신의 while 루프 내에서 $post_not_in[] = get_the_ID(); 놓습니다. 그 플러그인이 당신의 문제에 도움이되기를 바랍니다.

관련 문제