我在category.php文件中有这个代码,我需要按ASC对结果进行排序,因为现在结果的顺序相反。
提前致谢。
<ol class="search-results-list">
<?php
// Return Event Items
$i = 0;
while (have_posts()) : the_post();
if( get_post_type() == 'researcher' ) {
$i++; ?>
<li><strong><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></strong><br /> <?php print_excerpt(200); ?></li>
<?php }
endwhile;?>
<?php if( $i == 0 ) { ?><li><?php _e( 'No results were found.', 'qns' ); ?></li><?php } ?>
<!--END .search-results-list -->
</ol>
答案 0 :(得分:0)
将以下代码添加到functions.php文件中
if ( !function_exists( 'get_cat_id_by_slug' ) ) {
function get_cat_id_by_slug ($get_slug) {
$CatId = get_term_by( 'slug', $get_slug, 'category' );
$CatId = $CatId->term_id;
return $CatId;
}
}
将以下代码添加到您的category.php
中<?php
$category_id = get_cat_id_by_slug('researcher');
$args = 'cat=' . $category_id . 'order=asc';
query_posts($args);
if (have_posts()) :
while (have_posts()) : the_post();
?>
<ol class="search-results-list">
<li>
<strong>
<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
</strong><br />
<?php print_excerpt(200); ?>
</li>
</ol>
<?php
endwhile;
else :
?>
<ol class="search-results-list">
<li><?php _e( 'No results were found.', 'qns' ); ?></li>
</ol>
<?php
endif;
?>