WordPress obtains all tags of the current topic.

Source: Internet
Author: User
Tags php template

If you need to display all the tags added to the current category article on the category list page, you can easily read your favorite content. The following code can help you implement this function.


First, add the following functions to the topic functions. php template file:

Expand the code:

Next, add the following output code to the appropriate location of the topic archive. php template:

<? Php
$ Cat = single_cat_title ('', false );
$ Args = array ('Categories '=> get_cat_ID ($ cat ));
$ Tags = get_category_tags ($ args );
$ Content. = "<ul class = 'cat-tag'> ";
If (! Empty ($ tags )){
Foreach ($ tags as $ tag ){
$ Content. = "<li> <a href = \"". get_tag_link ($ tag-> term_id ). "\"> ". $ tag-> name. "</a> </li> ";
        }
    }
$ Content. = "</ul> ";
Echo $ content;
?>

Put my feeling in the header to call the function:

<? Php get_header ();?>

Which of the following is more suitable.

Finally, add the appropriate style:
. Cat-tag {
Float: left;
Width: 100%;
}
. Cat-tag li {
Float: left;
Margin: 0 5px;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.