2016-07-24 1 views
0

내가 (테마 패널에서 정의 된 범주를 호출)이 같은 코드를 제공하는 방법 :

<?php query_posts ('ignore_sticky_posts=1&showposts=1&cat='.get_cat_id 
($up_options->category1) 
); 

모든 것이 잘 작동을하지만 케이스에는 isset을 추가 할 필요가 카테고리가 정의되지 않았습니다.

<?php query_posts ('ignore_sticky_posts=1&showposts=1&cat='.get_cat_id(
(isset($up_options->category1) && $up_options->category1)) 
); 

을하지만 작동하지 않았다 : 나는 줄

은 다음과 같이는 isset. 아무도 도와 줄 수 있습니까? 나는 PHP가 처음이다.

도움 주셔서 감사합니다. 여기

전체 코드 :

<div class="wrapper"> 
    <?php query_posts ('ignore_sticky_posts=1&showposts=1&cat='.get_cat_id($up_options->category1));  
    if (have_posts()) : 
     while (have_posts()) : the_post();?> 
    <div class="inside"> 
     <div class="title"> 
      <h5> <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php echo substr(the_title('', '', false), 0, 75); ?>...</a> </h5> 
     </div> 
    </div> 
<?php endwhile; endif; wp_reset_query();?> 
</div> 

답변

0

다음과 같이하십시오 :

$cat_id = get_cat_ID($up_options->category1); 

if($cat_id != null){ 
    query_posts('ignore_sticky_posts=1&showposts=1&cat='.$cat_id); 
} else { 
    echo 'Category not defined'; 
} 

업데이트 여기

업데이트 질문에 따라 솔루션을하고있다 :

<?php 
    global $up_options; 
    $cat_id = get_cat_ID($up_options->category1); 

    if($cat_id != null) : 
     query_posts ('ignore_sticky_posts=1&showposts=1&cat='.$cat_id);  
     if (have_posts()) : 
      while (have_posts()) : the_post();?> 
     <div class="inside"> 
      <div class="title"> 
       <h5> 
        <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php echo substr(the_title('', '', false), 0, 75); ?>...</a> 
       </h5> 
      </div> 
     </div> 
    <?php endwhile; endif; wp_reset_query(); endif;?> 
+0

불행히도이 오류가 발생합니다. 알림 : 5 행의 객체가 아닌 객체의 속성을 얻으려고합니다. 5 행은 $ cat_id입니다. – Mailmulah

+0

동일한 코드를 테스트했는데 제대로 작동합니다. 코드를 공유 할 수 있습니까? – jakob

+0

업데이트 된 답변 확인 .. 나는 그것을 테스트하고 잘 작동합니다. – jakob