2014-02-19 41 views
0

出于某种原因,无论我做什么,似乎都没有工作将这些帖子按字母顺序排列。该代码是:在Wordpress中按姓名排序

<?php if (have_posts()) : while (have_posts()) : the_post(); 
array('posts_per_page' => -1, 'orderby'=> 'title', 'order' => 'ASC'); 
?> 
<li> 
<div class="sponsor-thumb"> 
<a href="'.get_permalink().'"> 
<?php the_post_thumbnail('category-thumb'); ?></a></div> 
<a href="<?php the_permalink() ?>"> 
<?php the_title(); ?> 
</a></li> 
<?php endwhile; else: ?> 
    <p><?php _e('Sorry, this page does not exist.'); ?></p> 
<?php endif; ?> 

回答

2

把这些代码,你必须是具有对查询没有任何影响。

达到你想要什么,你要使用WP_Query像这样:

$args = array('posts_per_page' => -1, 'orderby'=> 'title', 'order' => 'ASC'); 
$my_query = new WP_Query($args); 
if ($my_query->have_posts()) : 
    while ($my_query->have_posts()) : $my_query->the_post(); 
     // do stuff here 
    endwhile; 
endif; 
+0

难道我把它这样吗? <?php $ args = array('posts_per_page'=> -1,'orderby'=>'title','order'=>'ASC'); $ my_query = new WP_Query($ args); 如果($ my_query-> have_posts()): 而($ my_query-> have_posts()):$ my_query-> the_post(); //在这里做点东西 endwhile; endif; ?> – user3181828

+0

是的,它将需要去PHP标签 – BIOSTALL

+0

我有一个插件被激活,通过拖放排序的帖子。花了我几个小时才明白。烦人。 谢谢你的贡献。 – user3181828