我有以下URL:
http://example.com/?s=&cp_state=0&scat=16&sa=search&refine_search=yes
此代码位于search.php
:
<?php
$searchTxt = trim( strip_tags( esc_attr( get_search_query() ) ) );
$state_append = \'\';
$state = $_GET[\'cp_state\'];
if($state != \'0\')
$state_append = __(\'\', APP_TD).\' \' . $state;
$cat_id = $_GET[\'scat\'];
if ( $searchTxt == __(\'What are you looking for? \', APP_TD) || $searchTxt == __(\'[All]\', APP_TD) )
$searchTxt = \'*\';
if($searchTxt){
if($searchTxt == \'*\') {
if($cat = get_term_by(\'id\', $cat_id, \'ad_cat\')) {
printf( __("Ads %s %s ", APP_TD), $cat->name, $state_append, $wp_query->found_posts );
} else {
printf( __("Ads %s ", APP_TD), $state_append, $wp_query->found_posts );
}
} else {
printf( __("What are you looking for? \'%s\' %s ", APP_TD), $searchTxt, $state_append, $wp_query->found_posts );
}
}else{
$searchTxt = trim( strip_tags( esc_attr( get_search_query() ) ) );
printf( __("What are you looking for? \'%s\' %s ", APP_TD), $searchTxt, $state_append, $wp_query->found_posts );
}
echo $cat_id;
?>
我想获取URL的类别名称。我尝试使用
echo $cat_id
, 但它给我的是编号,而不是类别的名称。
如何“回显”类别的名称而不是编号?