The WordPress category page filters articles of the current category by month

Source: Internet
Author: User
You can use a small tool on the category. php page to archive articles and filter articles by month. Q: This filtering is a full-site article. How can I filter only the articles under the current category (no gadgets are required, as long as they are implemented) in category. the php page uses a small tool to archive articles so that you can filter articles by month.

Q: This is a full-site article. How can I filter only the articles under the current category (no gadgets are required as long as they are implemented)

Reply content:

You can use a small tool on the category. php page to archive articles and filter articles by month.

Q: This is a full-site article. How can I filter only the articles under the current category (no gadgets are required as long as they are implemented)

    add_filter('getarchives_where','current_category_posts_where');    function current_category_posts_where($where){        if(!is_category())            return;        $category = get_the_category();        $term_taxonomy_id = $category[0]->term_taxonomy_id;        global $wpdb;        return $where." AND {$wpdb->term_relationships}.term_taxonomy_id = {$term_taxonomy_id}";    }    add_filter('getarchives_join','current_category_posts_join');    function current_category_posts_join(){        if(!is_category())            return;        global $wpdb;        return "INNER JOIN {$wpdb->term_relationships} on {$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id";    }

Add functions. php to the topic.

Purpose:

When you access the category archive (in your case, it's category. php) page, such as the http://www.test.com/category/uncategorized, only the posts under uncategorized will be counted.

Is this effect. Baixiaohei.sinaapp.com

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.