Plug in free adds today's functions to wordpress in history

 Watson Blog September 18, 2017 12:38:52 WordPress comment three hundred and fifty-three Reading mode
abstract

It shows today in the history of the website. Therefore, friends who use this function need the website to be open for more than 1 year to have an effect.

introduce

Plug in free WordPress adds today's functions in history, which is very good for old stations (more than 1 year). Today, I will share this implementation method with you.

 Plug in free adds today's functions to wordpress in history

code

Add the following code to the function.php File.

  1. //Today in history
  2. function ? wp_today(){
  3. ???? global ? $wpdb ;
  4. ???? $post_year ?=? get_the_time('Y');
  5. ???? $post_month ?=? get_the_time('m');
  6. ???? $post_day ?=? get_the_time('j');
  7. ???? $sql ?=? "select?ID,?year(post_date_gmt)? as?h_year,?post_title,?comment_count?FROM?
  8. ????????????$ wpdb->posts?WHERE?post_password?=?''?AND?post_type?=?'post'?AND?post_status?=?'publish'
  9. ???????????? AND?year(post_date_gmt)!='$ post_year'?AND?month(post_date_gmt)='$post_month'? AND?day(post_date_gmt)='$post_day'
  10. ???????????? order?by?post_date_gmt?DESC?limit?5" ;
  11. ???? $histtory_post ?=? $wpdb ->get_results( $sql );
  12. ???? if (? $histtory_post ?) {
  13. ???????? foreach (? $histtory_post ? as ? $post ?) {
  14. ???????????? $h_year ?=? $post ->h_year;
  15. ???????????? $h_post_title ?=? $post ->post_title;
  16. ???????????? $h_permalink ?=? get_permalink(? $post ->ID?);
  17. ???????????? $h_comments ?=? $post ->comment_count;
  18. ???????????? $h_post ?.=? "<li><strong>$h_year:</strong>&nbsp;&nbsp;<a?href='" . $h_permalink . "'?title='" . $h_post_title . "'?target='_blank'>$h_post_title($h_comments)</a></li>" ;
  19. ????????}
  20. ????}
  21. ???? if ? (? $h_post ?) {
  22. ???????? $result ?=? "<h2>Today in history:</h2><ul>" . $h_post . "</ul>" ;
  23. ????}
  24. ???? return ? $result ;
  25. }
  26. function ? wp_today_auto( $content ){
  27. ???? if (?is_single()?) {
  28. ???????? $content ?=? $content .wp_today();
  29. ????}
  30. ???? return ? $content ;
  31. }
  32. add_filter('the_content',?' wp_today_auto',9999);

reminder

The above code is added to the end of the article by default. If you need to manually set the location, just delete the 26-32 lines of code, and then add the following code to the specified location:

  1. <? php? echo ? wp_today();??>

Extension

Plug in: WP Today of Liucheng blogger. You can download it yourself

AD Please click here to support Watson's blog!

 Watson Blog
  • This article is written by Published on September 18, 2017 12:38:52
  • This article is collected and sorted by the website of Mutual Benefit, and the email address for problem feedback is: wosnnet@foxmail.com , please keep the link of this article for reprinting: https://wosn.net/610.html

Comment