2012-08-12 5 views
0

나는이 코드를 사용하여 워드 프레스 에 사용자 정의 single.php 페이지 (카테고리 별)를 표시하고 잘 작동합니다.single.php의 사용자 정의 세로 막대

get_header(); ?> 

     <div id="container"> 
      <div id="content" role="main"> 

      <?php 
       $post = $wp_query->post; 

       if (in_category('4')) { 
        include(TEMPLATEPATH.'/loop-single-recept.php'); 
       } elseif (in_category('7')) { 
        include(TEMPLATEPATH.'/loop-single.php'); 
       } else { 
        include(TEMPLATEPATH.'/loop-single.php'); 
       } 
       ?> 


      </div><!-- #content --> 
     </div><!-- #container --> 

<?php get_sidebar(); ?> 
<?php get_footer(); ?> 

그러나 나는 또한 각 single.php 페이지에 사용자 정의 사이드 바를 표시하고 싶습니다.

답변

2

여러 사이드 바 파일을 생성 한 다음 다른 기사를 만들 예를 들어 <?php get_sidebar() ?>

에 (일반적으로 빈) 인수를 사용하여 전화를 호출 사이드 바 alternative.php을 한 후 사용하여 호출 할 수 있습니다 <?php get_sidebar('alternative'); ?>

코드가 다음과 같을 수 있습니다. 나는 그것의 문제를 만들고 있지 않다 그런데

 <?php 

      if (in_category('4')) { 
       get_sidebar(); 
      } elseif (in_category('7')) { 
       get_sidebar('alternative'); 
      } else { 
       get_sidebar('alternative'); 
      } 

     ?> 

하지만 응답 사람을 넣어 것입니다 당신이 답의 일부를 수용 대해 생각해야 - Stackoverflow Answers

0

때때로 in_category은()하지 않습니다 작동하는 것처럼 보입니다. $ wp_query 변수에서 카테고리 이름을 가져 와서 내 자신의 파일을 포함하고 싶습니다.

if($wp_query->query['category_name'] == 'your-category-name-1') { 

    include_once('sidebar-one.php'); 

} else if($wp_query->query['category_name'] == 'your-category-name-2') { 

    include_once('sidebar-two.php'); 

} else { 

    include_once('sidebar-three.php'); 

}