2

好吧,此代码获取类别列表并将其显示在分配帖子的主题中。我想将 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' )
            );
        ?>

还有什么办法吗?

4

2 回答 2

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(),要在循环外使用它,您必须提供帖子 ID,get_the_category()因此它应该是get_the_category( $post->ID )

于 2012-06-16T21:13:28.297 回答
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' )
            );
        ?>
于 2017-07-08T16:30:09.520 回答