好吧,此代码获取类别列表并将其显示在分配帖子的主题中。我想在此列表中添加nofollow标签。我上网,找不到解决方案。我找到的唯一解决方案是修改wordpress核心文件。但我不想修改核心文件。
<footer class="entry-meta">
<?php
/* translators: used between list items, there is a space after the comma */
$category_list = get_the_category_list( __( ', ', 'basically' ) );
$meta_text = __( 'Category: %1$s', 'basically' );
printf(
$meta_text,
$category_list,
get_permalink(),
the_title_attribute( 'echo=0' )
);
?>
还有其他方式吗?
答案 0 :(得分:1)
<?php
foreach( (get_the_category() ) as $category ) {
$category_link[] = '<a href="' . get_category_link( $category->cat_ID ) . '"'
. ' title="' . $category->cat_name . '" rel="nofollow">'
. $category->cat_name . '</a>';
}
printf( __( 'Category: %1$s', 'basically' ), implode( ', ', $category_link ) );
?>
它可以在the_loop()
内使用,要在循环外使用它,您必须在get_the_category()
上提供帖子ID,因此它应该是get_the_category( $post->ID )
。
答案 1 :(得分:0)
试试这个:
<footer class="entry-meta">
<?php
/* translators: used between list items, there is a space after the comma */
$cat_list = get_the_category_list( __( ', ', 'basically' ) );
$category_list = str_replace('rel="category tag"','rel="category tag nofollow"',$cat_list);
$meta_text = __( 'Category: %1$s', 'basically' );
printf(
$meta_text,
$category_list,
get_permalink(),
the_title_attribute( 'echo=0' )
);
?>