Wordpress 如何在此代码上对类别结果进行排序?
我在category.php文件中有这段代码,我需要按ASC对结果进行排序,因为现在结果的顺序是相反的 提前谢谢Wordpress 如何在此代码上对类别结果进行排序?,wordpress,categories,Wordpress,Categories,我在category.php文件中有这段代码,我需要按ASC对结果进行排序,因为现在结果的顺序是相反的 提前谢谢 <ol class="search-results-list"> <?php // Return Event Items $i = 0; while (have_posts()) : the_post();
<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>
将以下代码添加到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;
?>
非常感谢您,但我很抱歉,这项服务不起作用,或者存在某种冲突。添加此代码将使整个网站完全空白!我测试了代码,它运行良好。我不知道这是你的自定义摘录还是其他东西没有正确连接@用户3489056