Specific
Get current Category:
The code is as follows |
Copy Code |
<?php the_category_id (False)?> |
We can customize a function to get the ID of the root category on the basis of getting this category ID:
The code is as follows |
Copy Code |
function get_category_root_id ($CAT) { $this _category = get_category ($cat); Get current category while ($this _category->category_parent)//If the current classification has superior classification, the loop { $this _category = get_category ($this _category->category_parent); Set current category to superior category (climb up) } return $this _category->term_id; Returns the ID number of the root category } |
Finally, the root classification of the current article can be represented by a function get_category_root_id (the_category_id (false)).
Also share a category related hot articles using popularity contest Plug-ins to sample
A plug-in has 2 function available
Akpc_most_popular_in_cat and Akpc_most_popular, respectively, specify a category ID or take the current category and all rankings.
But Akpc_most_popular_in_cat's problem is that the original SQL statement is in the Show_top_ranked_in_cat SQL is
The code is as follows |
Copy Code |
WHERE tt.term_id = ' ". Intval ($cat _id)." ' |
In this way, you can only find in one category and need to be modified to support multiple category IDs. Changed to the following
code is as follows |
copy code |
WHERE tt.term_id in (". $cat _id.") |