我不知道你为什么需要这个,或者你在这里的确切用例是什么,但简而言之,the_category()
只需回显get_the_category_list()
其中使用get_category_link()
其中使用get_term_link()
获取类别页面的URL。
如果需要更改链接到类别页面的URL,您应该在这里查看。在里面get_term_link()
, 有一个term_link
filter 可用于更改为特定术语/类别返回的URL
return apply_filters( \'term_link\', $termlink, $term, $taxonomy );
因此,如果需要更改
category
分类法,您可以尝试以下代码(
NOTE: 代码未经测试
add_filter( \'term_link\', function ( $termlink, $term, $taxonomy )
{
// Check if we have the correct term and taxonomy, if not, bail early
if ( $term->term_id != 1 // Check if current term is 1 or not
&& $taxonomy != \'category\' // Check if the current term is from the taxonomy category
)
return $termlink;
// If we came to this point, we have the desired term and taxonomy, so lets alter the URL
// Here should be the code to construct your new URL, you need to work on this
$termlink = \'VALUE_OF_NEW_URL\'; // This will be the new URL our term to link to its term page
return $termlink;
}, 10, 3 );