2013-06-30 1 views
0

나는 기본적으로 나는 WordPress의 특정 카테고리에서 상위 3 개의 스틱 게시물을 가져 와서 그들을 표시하려고 노력하고있다. 아래에 몇 가지 코드가 있습니다. 그러나이 범주에서 끈적 거리는 것으로 표시된 특정 게시물뿐만 아니라 모든 게시물을 가져옵니다.카테고리에서 WordPress 끈적한 게시물을 가져 오기

<?php $sticky=get_option('sticky_posts'); 
$query_args=array(
'post__in' => $sticky, 
'category__in'=>array($category) 
); 
$the_query = new WP_Query($query_args); ?> 
<?php $count = 0; ?> 
<?php while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate =  $post->ID; ?> 
<?php $count++; ?> 

<?php if ($count == 1) : ?> 
    <div class="featurethumb"><?php the_post_thumbnail(array(306,306), array ('class' => 'featurethumb')); ?> 
<div class="featuretitle-bg"><div class="featuretitle"><a title="<?php the_title(); ?>" href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></div> 
<div class="featured-desc"><?php the_excerpt(__('(more…)')); ?></div></div> 
</div> 
<?php elseif ($count == 2) : ?> 
    <div class="index-thumb"><?php the_post_thumbnail(array(100,100), array  ('class' => 'alignleft1')); ?></div> 
<div class="indexblog-title"><a title="<?php the_title(); ?>" href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></div> 
<?php the_excerpt(__('(more…)')); ?> 
<?php else : ?> 
    <div class="index-thumb"><?php the_post_thumbnail(array(100,100), array ('class' => 'alignleft2')); ?></div> 
<div class="indexblog-title"><a title="<?php the_title(); ?>" href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></div> 
<?php the_excerpt(__('(more…)')); ?> 
<?php endif; ?> 

<?php endwhile; ?> 
+0

여기서'$ category'는 정의 되었습니까? '$ the_query'와'my_query'를 섞어서 사용하고 있습니다. – RST

답변

1

나는 $ 카테고리를 RST라고 언급 한 곳에서 정의했다고 가정합니다.

<?php 

/* Get all sticky posts */ 
$sticky = get_option('sticky_posts'); 

/* Sort the stickies with the newest ones at the top */ 
rsort($sticky); 

/* Get the 5 newest stickies (change 5 for a different number) */ 
$sticky = array_slice($sticky, 0, 5); 

/* Query sticky posts */ 
$query_args = array( 
         'post__in' => $sticky, 
         'category__in'=>array($category) 
        ); 
?> 

$my_query = new WP_Query($query_args); ?> 
<?php while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate =  $post->ID; ?>