2015-01-09 3 views
-2

나는 워드 프레스를 설치했습니다. 이제 몇 가지 설명과 함께 카테고리가있는 관련 게시물을 추가하고 싶습니다. 그래서 이것을 만들었습니다.카테고리 별 PHP 관련 게시물?

<div class="related"> 
    <h3>Related Articles</h3> 
    <?php 
     $orig_post = $post; 
     global $post; 
     $tags = wp_get_post_categories($post->ID); 

     if ($tags) { 
      $tag_ids = array(); 
     foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id; 
      $args=array(
       'tag__in' => $tag_ids, 
       'post__not_in' => array($post->ID), 
       'posts_per_page'=>4, // Number of related posts to display. 
       'caller_get_posts'=>1 
      ); 

     $my_query = new wp_query($args); 

     while($my_query->have_posts()) { 
      $my_query->the_post(); 
     ?> 

     <div class="relatedthumb"> 
      <a rel="external" href="<? the_permalink()?>"><?php the_post_thumbnail(array(150,100)); ?><br /> 
      <?php the_title(); ?> 
      </a> 
     </div> 

이제이 코드를 내 wordpress 블로그에 붙여 넣으면 도움이되지 않습니다. 이 코드에서 잘못된 점은 무엇입니까? 당신은 관련 게시물을 표시하여 원하는 목적지

+4

**이 작동하지 않습니다 ** - 당신이 집에서 숙박을 의미하고 TV를 시청? 또는 어떤 오류가 발생하고 있습니까? – violator667

+0

wp_get_post_categories ($ post-> ID), 'numberposts'=> 5, 'post__not_in'=> 배열 ($ post-> ID))); if ($ related) foreach ($ related as $ post) { setup_postdata ($ post); ?>

+1

우선, 주석에 코드를 게시하지 마십시오. 읽을 수 없습니다. 귀하의 질문에 ** [편집]을 제출하고 모든 관련 코드를 ** 게재하십시오. 둘째, * 작동하지 않습니다. * 유효한 문제 설명이 아닙니다. 정확히 ** 어떤 일이 일어나고 있지 않거나 일어나지 않아야하는 일이 일어나지 않아야합니다. 이 질문에 [편집] 형태로 대답하십시오. –

답변

0

봅니다 루프 후 single.php 내부에이 코드를 추가하는

<?php 

    $related = get_posts(array('category__in' => wp_get_post_categories($post->ID), 'numberposts' => 4, 'post__not_in' => array($post->ID))); 
    if($related) foreach($related as $post) { 
    setup_postdata($post); ?> 
    <ul> 
      <li> 
      <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a> 
       <?php the_content('Read the rest of this entry &raquo;'); ?> 
      </li> 
     </ul> 
    <?php } 
    wp_reset_postdata(); ?> 
관련 문제