It is still necessary to archive WordPress articles. especially when there are too many articles, you can easily find the articles you want to find using archive. There are many plug-ins on the Internet to implement this function, however, we like to do so, so we don't need plug-ins, but use code to implement them.
It is still necessary to archive WordPress articles. especially when there are too many articles, you can easily find the articles you want to find using archive. There are many plug-ins on the Internet to implement this function, however, we like to do so, so we don't need plug-ins, but use code to implement them.
Features:
1. this archive function will generate a table SHe_archives_25216 in the database, which is used to save the html generated when the article is newly published/deleted, which mainly speeds up access, you do not need to query the database every time to generate an archive.
2. display the number of articles per month
3. display the number of comments for each article
Effect: See my blog document archiving
Description: I added the jQuery sliding effect. the jQ code comes from the network and is slightly modified.
The detailed steps are as follows:
1. run the following archives_list_SHe function code into the topic's functions. php.
Function archives_list_SHe () {global $ wpdb, $ month; $ lastpost = $ wpdb-> get_var ("select id from $ wpdb-> posts WHERE post_date <'". current_time ('mysql '). "'AND post_status = 'Publish' AND post_type = 'post' AND post_password = ''Order BY post_date desc limit 1"); $ output = get_option ('She _ archives _'. $ lastpost); if (empty ($ output) {$ output = ''; $ wpdb-> query ("delete from $ wpdb-> options WHERE option_name LIKE 'she _ archives _ % '"); $ q = "select distinct year (post_date) AS year, MONTH (post_date) AS month, count (ID) as posts FROM $ wpdb-> posts p WHERE post_date <'". current_time ('mysql '). "'AND post_status = 'Publish' AND post_type = 'post' AND post_password = ''group by year (post_date), MONTH (post_date) order by post_date DESC "; $ monthresults = $ wpdb-> get_results ($ q); if ($ monthresults) {foreach ($ monthresults as $ monthresult) {$ thismonth = zeroise ($ monthresult-> month, 2); $ thisyear = $ monthresult-> year; $ q = "select id, post_date, post_title, comment_count FROM $ wpdb-> posts p WHERE post_date LIKE '$ thisyear-$ thismonth-%' AND post_date AND post_status = 'Publish 'AND post_type = 'post' AND post_password = ''ORDER BY post_date DESC "; $ postresults = $ wpdb-> get_results ($ q); if ($ postresults) {$ text = sprintf ('% s % d ', $ month [zeroise ($ monthresult-> month, 2)], $ monthresult-> year); $ postcount = count ($ postresults); $ output. ='
- '. $ Text.' ('. count ($ postresults).' article)
'. "\ N"; foreach ($ postresults as $ postresult) {if ($ postresult-> post_date! = '2014-00-00 00:00:00 ') {$ url = get_permalink ($ postresult-> ID); $ arc_title = $ postresult-> post_title; if ($ arc_title) $ text = wptexturize (strip_tags ($ arc_title); else $ text = $ postresult-> ID; $ title_text = 'View this post ,"'. wp_specialchars ($ text, 1 ). '"'; $ output. ='
- '. Mysql2date ('D Day', $ postresult-> post_date ). ':'. "$ text"; $ output. = '('. $ postresult-> comment_count. ')'; $ output. ='
'. "\ N" ;}}$ output. ='
'. "\ N";} update_option ('She _ archives _'. $ lastpost, $ output);} else {$ output = 'Sorry, no posts matched your criteria. '. "\ n" ;}} echo $ output;} 2. copy the page of a topic. php is renamed archives. php, and then add:
Then find , Add the following code below
Expand/contract all
Delete the comment section, add a new page to the wp background, and select archives in the template on the right.
3. if your topic is loaded with the jQuery library, you can continue to add the following jQ code to achieve the sliding scaling effect.
/* JQ scaling */(('{expand_collapse,.archives-yearmonth'}.css ({cursor: "s-resize"}); $ ('# archives ul li ul. archives-monthlisting '). hide (); $ ('# archives ul li ul. archives-monthlisting: first '). show (); $ ('# archives ul li span. archives-yearmonth '). click (function () {$ (this ). next (). slideToggle ('Fast '); return false ;}); // The following is a global operation $ (' # expand_collapse '). toggle (function () {$ ('# archives ul li ul. archives-monthlisting '). slideDown ('save');}, function () {$ ('# archives ul li ul. archives-monthlisting '). slideUp ('Fast ');});
Note: css styles can be defined through # archive.