문제

상단에 카테고리 목록이있는 페이지가 있으며 일반적으로 아래에 게시물을 나열해야합니다. 카테고리 목록은 다음을 사용하여 작성됩니다.

    <?php $display_categories = array(4,7,8,9,21,1); $i = 1;
foreach ($display_categories as $category) { ?>
<?php single_cat_title(); ?> //etc
</div>
    <?php } ?>

그러나 이것은 사후 루프 주문 게시물을 카테고리별로 만드는 것 같습니다. 내림차순 주문으로 카테고리 순서와 주문을 무시하고 싶습니다. 문서에 따르면 query_posts ()를 두 번 사용할 수 없으므로 경우에 따라 새로운 WP_Query를 만들었습니다.

    <?php $q = new WP_Query("cat=-1&showposts=15&orderby=date&order=DESC");
    if ( $q->have_posts() ) : while ( $q->have_posts() ) : $q->the_post(); ?>
    the_title(); // etc
    endwhile; endif; ?>

그러나 이것 아직 카테고리 (위의 목록과 동일한 순서)로 주문한 다음 날짜와는 달리 날짜에 따라 주문하는 것 같습니다.

도움이 되었습니까?

해결책

나는 이것에도 문제가 있었다.

이 시도:

      <?php
     global $post;
     $myposts = get_posts('numberposts=5');

     foreach($myposts as $post) : 
     setup_postdata($post);
     ?>
       <div <?php post_class(); ?>>
         <div class="title">
           <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
           <p class="small"><?php the_time('F j, Y'); ?> by <?php the_author(); ?></p>
         </div>
         <?php the_excerpt(); ?>
       </div>
 <?php 
     endforeach; 
 ?> 

중요한 줄은 'Global $ Post;'입니다.

글로벌 쿼리를 재설정해야합니다. 'the_author ()'또는 'the_content ()'와 같은 함수에 액세스하려면 'setup_postdata ($ post) 메소드가 필요합니다.

-Chris

다른 팁

WordPress에 대한 경험이 없지만 몇 가지 가능성이 있습니다.

  1. 당신이하는 문자열에서 "주문"매개 변수를 두 번 정의합니다. query_posts() 그게 문제가되는지 아닌지 모르겠습니다.
  2. 또한 "Show"는 유효한 매개 변수가 아니며 "ShowPosts"를 찾고있을 수 있습니다.

매개 변수와 그 효과는 다음과 같습니다. http://codex.wordpress.org/template_tags/query_posts#parameters

query_posts는 때때로 까다 롭습니다. 이와 같은 것을 시도하고 그것이 작동하는지 확인하십시오.

query_posts(array('category__not_in'=>array(1),
                  'showposts'=>15,
                  'orderby'=>date,
                  'order'=>DESC));

문제가되지 않기 때문에 다음과 같은 두 번째 루프에 update_post_caches ($ posts)를 추가하십시오.

<?php $q = new WP_Query("cat=-1&showposts=15&orderby=date&order=DESC");
if ( $q->have_posts() ) : while ( $q->have_posts() ) : $q->the_post(); update_post_caches($posts); ?>
the_title(); // etc
endwhile; endif; ?>

아마도 이것 일부 플러그인 문제를 해결합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top