WordPress站内权重通报:”历史上的本日”文章挪用要领增添

我们在应用wordpress搭建网站最早运营的时刻会发明,wordpress主题自带的一些经常应用恪守,关于用户体验或是内容…

我们在应用网站最早运营的时刻会发明,自带的一些经常应用恪守,关于用户体验或是内容展示来将是远远不够的,我们还须要手动界说一些如随机内容或是热点帖子等信息增加到分歧职位的模块下,那本日大挖给人人推荐一个不错的要领,对照有意思相宜稳固运营三至四年的资深站点,叫做“历史上的本日”他能够也许依据以后月份挪用出客岁或是前年的同一个宣布的一些文章内容。能够也许有较的增加站内权重通报。

我们能够也许经由进程以下的要领举行恪守增加,同时也能够也许应用对照疾速的插件要领完成,插件名称为This Day In History。

将以下代码加入到以后wordpress主题的Functions.php文件中。

function wp_today(){ global $wpdb; $post_year = get_the_time(‘Y’); $post_month = get_the_time(‘m’); $post_day = get_the_time(‘j’); $sql = “select ID, year(post_date_gmt) as h_year, post_title, comment_count FROM $wpdb->posts WHERE post_password = ” AND post_type = ‘post’ AND post_status = ‘publish’ AND year(post_date_gmt)!=’$post_year’ AND month(post_date_gmt)=’$post_month’ AND day(post_date_gmt)=’$post_day’ order by post_date_gmt DESC limit 5″; $histtory_post = $wpdb->get_results($sql); if( $histtory_post ){ foreach( $histtory_post as $post ){ $h_year = $post->h_year; $h_post_title = $post->post_title; $h_permalink = get_permalink( $post->ID ); $h_comments = $post->comment_count; $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>”; } } if ( $h_post ){ $result = “<h2>历史上的本日:</h2><ul>”.$h_post.”</ul>”; } return $result; } function wp_today_auto($content){ if( is_single() ){ $content = $content.wp_today(); } return $content; } add_filter(‘the_content’, ‘wp_today_auto’,9999);

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 function wp_today ( ) { global $ wpdb ; $ post_year = get_the_time ( ‘Y’ ) ; $ post_month = get_the_time ( ‘m’ ) ; $ post_day = get_the_time ( ‘j’ ) ; $ sql = “select ID, year(post_date_gmt) as h_year, post_title, comment_count FROM $wpdb->posts WHERE post_password = ” AND post_type = ‘post’ AND post_status = ‘publish’ AND year(post_date_gmt)!=’$post_year’ AND month(post_date_gmt)=’$post_month’ AND day(post_date_gmt)=’$post_day’ order by post_date_gmt DESC limit 5″ ; $ histtory_post = $ wpdb -> get_results ( $ sql ) ; if ( $ histtory _post ) { foreach ( $ histtory_post as $ post ) { $ h_year = $ post -> h_year ; $ h_post_title = $ post -> post_title ; $ h_permalink = get_permalink ( $ post -> ID ) ; $ h_comments = $ post -> comment_count ; $ 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>” ; } } if ( $ h _post ) { $ result = “<h2>历史上的本日:</h2><ul>” . $ h_post . “</ul>” ; } return $ result ; } function wp_today_auto ( $ content ) { if ( is_single ( ) ) { $ content = $ content . wp_today ( ) ; } return $ content ; } add_filter ( ‘the_content’ , ‘wp_today_auto’ , 9999 ) ;

在须要展示的职位上增加以下挪用代码便可同时我们须要对以上代码举行css款式的调解。就能够也许完成恪守了

<?php echo wp_today(); ?>

1 <?php echo wp_today ( ) ; ?>
「点点赞赏,手留余香」

    还没有人赞赏,快来当第一个赞赏的人吧!