Wordpress bulletin board database cache

Source: Internet
Author: User
I thought about 8.2 million hair, but I couldn't help it. the wordpress bulletin board database cache version improves willin's database cache code. When a comment is added, the cache is refreshed. The bulletin board only displays the Administrator's main comments, and the following code is directly placed in functions. in php, and then throw a sentence where the announcement board needs to be displayed? Phpbulletin

I thought about 8.2 million hair, but I couldn't help it. the wordpress bulletin board database cache version improves willin's database cache code. When a comment is added, the cache is refreshed. The bulletin board only displays the Administrator's main comments, and the following code is directly placed in functions. in php, and then throw a sentence where the announcement board needs to be displayed? Php bulletin

I thought about 8.2 million hair, but I couldn't help it.

Wordpress bulletin board database cache
  1. Improved willin's database cache code and added the cache refresh function when deleting comments.
  2. Only the Administrator comments are displayed on the bulletin board, but not subcomments.
  3. The following code is directly placed in functions. php, and then you can throw a sentence where you need to display the announcement board. .
    Before usingpost_id' => 18841884 to your bulletin board page id
Function bulletin () {if (! $ Announcement = get_option ('clear _ buffer') {$ args = array ('Post _ id' => 1884, 'number' => 5, 'User _ id' => '1', parent => '0'); $ announcement = ''; $ comments = get_comments ($ args ); foreach ($ comments as $ comment) {$ announcement. ='
  • '. Human_time_diff (get_comment_date ('U', $ comment-> comment_ID), current_time ('timestamp ')). 'pre '. ''. get_comment_date ('H: I ', $ comment-> comment_ID ). '-comment_post_ID ). "# comment -". $ comment-> comment_ID. '"title = "'. strip_tags ($ comment-> comment_content ). '"> '. convert_smilies ($ comment-> comment_content ).'
  • ';} Update_option ('clear _ buffer', $ announcement);} echo $ announcement;} function clear_buffer_function () {update_option ('clear _ buffer ',''); // clear cache} add_action ('comment _ Post', 'clear _ buffer_function '); // release a new comment and clear the cache add_action ('edit _ comment ', 'Clear _ buffer_function '); // The comment is edited. The add_action ('trashed _ comment', 'clear _ buffer_function') is cleared. // The comment is moved to the recycle bin to clear the cache.
    Principle.

    You can use update_option to add tables to the database for caching. This code is universal. If you want to implement caching for other functions, you only need to refer to this example. For example, the original code on the bulletin board is:

    Function bulletin () {$ args = array ('Post _ id' => 1884, 'number' => 5, 'user _ id' => '1 ', parent => '0'); $ announcement = ''; $ comments = get_comments ($ args); foreach ($ comments as $ comment) {$ announcement. ='
  • '. Human_time_diff (get_comment_date ('U', $ comment-> comment_ID), current_time ('timestamp ')). 'pre '. ''. get_comment_date ('H: I ', $ comment-> comment_ID ). '-comment_post_ID ). "# comment -". $ comment-> comment_ID. '"title = "'. strip_tags ($ comment-> comment_content ). '"> '. convert_smilies ($ comment-> comment_content ).'
  • ';} Echo $ announcement ;}

    You can compare the code at the beginning of the article to find the fault, and find the fault (that is, the place I marked in red) is the general code of the database cache.
    Similarly, more functions can be cached. To Cache different functions, you only needif (!$announcement = get_option('clear_buffer'))Changeif (!$announcement = get_option('clear_buffer2')),
    Then

    function clear_buffer_function() {update_option('clear_buffer', '');  }

    Change

    Function clear_buffer_function () {update_option ('clear _ buffer', ''); update_option ('clear _ buffer2 ',''); // and so on}

    Other places do not move.

    Benefits

    Today's code is a bit long and complicated. In order to reward all the friends who have carefully read it, send a group of benefits...

    Original article address: Cache version of the wordpress bulletin board database. Thank you for sharing it with me.

    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.