well, this code fetches the category list and display it in the theme in which the post is assigned. I want to add nofollow tag to this out list. I surfed the net and couldn't find a solution. The only solution I found was to modify the wordpress core files. But I don't want to modify the core files.
<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' )
);
?>
Any other way?
<?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 ) );
?>
It will work inside the_loop()
, to use it outside the loop you have to provide the post id on get_the_category()
so it should be get_the_category( $post->ID )
.