Function of WordPress to obtain the root category id of the comment and current category

Source: Internet
Author: User
Tags comments

1. Add the recent_comments.php file to the template. The code is as follows:

The code is as follows: Copy code

<? Php
$ Comments = get_comments ('number = 10 & status = approve ');
$ True_comment_count = 0;
Foreach ($ comments as $ comment ):
$ Comment_type = get_comment_type ();
If ($ comment_type = 'Comment '){
$ True_comment_count = $ true_comment_count + 1;
$ Comm_title = get_the_title ($ comment-> comment_post_ID );
$ Comm_link = get_comment_link ($ comment-> comment_ID );
$ Comm_comm_temp = get_comment ($ comment-> comment_ID, ARRAY_A );
$ Comm_content = $ comm_comm_temp ['Comment _ content'];
?>
<Li style = "line-height: 1.5em; border-bottom: 1px dashed #1A8EE5;"> <span class = "comment_author"> [<em style = "color: # D16A1A; text-weight: blod; "> <? Php echo ($ comment-> comment_author)?> </Em>] </span> On: <a href = "<? Php echo ($ comm_link)?> "Title =" <? Php comment_excerpt ();?> "> <? Php echo $ comm_title?> </A> <br/> <strong> Say: </strong> <? Php echo $ comm_content?> </Li>
<? Php
    }
If ($ true_comment_count = 5) break;
Endforeach;
?>

2. Insert the following content in the position you want to display in sidebar. php:

The code is as follows: Copy code

<? Php include (TEMPLATEPATH. '/recent_comments.php');?>


Function of WordPress to obtain the root category id of the current category

I only had to do it myself. Then I used the following two methods to solve the problem!

The code is as follows: Copy code

Function get_category_root_id ($ cat)
{
$ This_category = get_category ($ cat); // Obtain the current category
While ($ this_category-> category_parent) // if the current category has a parent category
 {
$ This_category = get_category ($ this_category-> category_parent); // set the current category to the upper-level category (climb up)
 }
Return $ this_category-> term_id; // return the ID of the root category
}
 
Function fengzx_get_category_ID (){
$ Category = get_the_category ();
Return $ category [0]-> cat_ID;
}

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.