I have recently studied the CMS topic of WordPress. One of the reasons is that I have already said that I will not publish a Chinese WordPress blog topic easily, because I really think it is worthless, in a few days, the bottom of the copyright will disappear. For a CMS topic, the category of the home page is naturally the most frustrating. After a few tossing times, I finally learned the new PHP skills for getting the names and IDs of all WordPress categories. GET ~ The main body of the code is WPDAXUE, but I don't know if you find it. In fact, WPDAXUE cannot be used, and there are all fatal PHP syntax errors-I can't speak out, after several changes, the code posted below will definitely be able to withstand the test. I will also take a note to make everyone feel free to use it ~ The first step is to add a large part of code to the function. Of course you can do it without adding it. You can also paste it when you need to call it.
The code is as follows: |
Copy code |
Function zzfly_show_category (){ Global $ wpdb; $ Request = "SELECT $ wpdb-> terms. term_id, name FROM $ wpdb-> terms "; $ Request. = "left join $ wpdb-> term_taxonomy ON $ wpdb-> term_taxonomy.term_id = $ wpdb-> terms. term_id "; $ Request. = "WHERE $ wpdb-> term_taxonomy.taxonomy = 'Category '"; $ Request. = "order by term_id asc "; $ Categorys = $ wpdb-> get_results ($ request ); Foreach ($ categorys as $ category) {// call the menu $ Output = '<span> '. $ category-> name. "(<font style =" color: red; "> ". $ category-> term_id. '</font>) </span> '; Echo $ output; |
After adding the above code to a proper position, you can use the following code to display the code as needed.
The code is as follows: |
Copy code |
<? Php zzfly_show_category ();?> |
After adding the above code to a proper position, you can use the following code to display the code where it needs to be displayed. Yes, that's all about this large piece of code, I have been tossing for nearly an hour. Most of the code comes from the great WPDAXUE, but I fixed several bugs. Today I am here.