Nasıl bir önceki mesaj sorgu geçersiz kılmak için wordpress alabilirim?

3 Cevap php

Ben üst bir kategori listesine sahip bir sayfa var ve normalde onun altındaki mesajları listesi gerekir. Kategori listesi kullanılarak oluşturulur:

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

Ancak, bu kategorideki tarafından yazılan döngü sipariş Mesajları yapmak gibi görünüyor. Ben azalan tarihe göre kategori sıralama ve düzeni göz ardı etmek istiyorum. Ben iki kez query_posts () kullanamazsınız dokümanlar göre bu yana yeni bir WP_Query yarattı, yani sadece durumda ettik.

    <?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; ?>

Ancak, bu still, sadece tarihe karşı, tarihe ve sonra kategoriye göre (yukarıdaki listede aynı sırayı) sipariş gibi görünüyor.

3 Cevap

Ben de daha önce bu sorunları yaşadım.

Bu deneyin:

      <?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; 
 ?>

Önemli satır 'küresel $ post;' dir.

Yani global sorgu sıfırlamak gerekir. The_author () 'veya' the_content () 'setup_postdata ($ post) yöntemi gibi fonksiyonlara erişim vermek için gerekli olduğunu'.

-Chris

Ben wordpress ile herhangi bir deneyim, ama olasılıklar bir çift yok:

  1. Eğer bir sorununuz ya da değil neden olmadığını bilmiyorum, query_posts() ile aradığınız dize iki kez "düzen" parametresini tanımlar.
  2. Yanı sıra, "show" siz "showPosts" için arıyor olabilir, geçerli bir parametre değildir.

Parametreler ve etkileri burada açıklanmıştır: http://codex.wordpress.org/Template_Tags/query_posts#Parameters

query_posts bazen titiz. Böyle bir şey denemek ve görmek eğer o inşaat:

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

Bu sorun değil, çünkü bu gibi ikinci döngü update_post_caches ($ mesaj) eklemeyi deneyin:

<?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; ?>

Sözde bu solves some plugin problems.