admin管理员组

文章数量:1327801

I have created a new post type named "Project". And I registered 1 taxonomy "Tags" in it as follows:

/view/844258b1

I entered the tags into 1 article in post type "Project".

If you want to enter an article, it will display all the tags in that article.

Can someone help me. Thank you!

I have created a new post type named "Project". And I registered 1 taxonomy "Tags" in it as follows:

https://pastecode.xyz/view/844258b1

I entered the tags into 1 article in post type "Project".

If you want to enter an article, it will display all the tags in that article.

Can someone help me. Thank you!

Share Improve this question edited Mar 29, 2019 at 10:28 Johansson 15.4k11 gold badges43 silver badges79 bronze badges asked Mar 29, 2019 at 7:54 Hoàng Năng HưngHoàng Năng Hưng 11 bronze badge 1
  • Please include the code in your post and highlight it. What values does this link have as soon as it goes 404? – norman.lol Commented Mar 29, 2019 at 18:52
Add a comment  | 

3 Answers 3

Reset to default 1

Considering you mention having registered a custom taxonomy instead of using the native tags, the functions the_tags() and get_tags will not work.

you need to get your custom taxonomy terms by using get_the terms(). Usage is not much different from using native tags, but you have to pass the post_type as a variable. See the Wordpress codex on this: https://developer.wordpress/reference/functions/get_the_terms/

You have to be careful when creating a custom post type with taxonomy and the same namespace "tags", since tags are already registered by WordPress default for the post type posts. Maybe the renaming of the taxonomy to project-tags or something else would make sense. Otherwise the taxonomy will be mixed up by WordPress.

To show all tags you can use PHP:

the_tags('<ul class="taglist"><li>', '</li><li>', '</li></ul>');

Note: This function must be within the loop (archive.php or single.php).

Check out get_the_tag_list() to retrieve all the tags:

https://codex.wordpress/Function_Reference/get_the_tag_list

Examples:

$separate_meta = __( ', ' );
echo $tags_list = get_the_tag_list( '', $separate_meta );

OR:

<?php
 $tags = get_tags();
 if ($tags) {?>
  <ul class="tags">
  <?php
    foreach ($tags as $tag) {
    echo '<li><a href="' . get_tag_link( $tag->term_id ) . '" 
    title="' . sprintf( __( "View all posts in %s" ), $tag->name ) . '" ' . '>' . $tag->name.'</a></li>';
  }
  ?>
  </ul>
<?php }?>

本文标签: Show all Tags in each post