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; } |