begin主题最近读者源码解析

2021年3月8日22:35:33 6 1,693 views

最近浏览源代码文件位子,\pages\template-mostactive.php

核心代码

<div id="primary" class="content-area">
	<main id="main" class="site-main" role="main">
		<?php while ( have_posts() ) : the_post(); ?>
			<div class="comment-authors">
				<?php the_content(); ?>
			</div>
		<?php endwhile; ?>
		<?php top_comments(98); ?>
		<div class="clear"></div>
	</main>
</div>

其实真正的核心代码不是在这里的,里面的 <?php top_comments(98); ?>  这才是核心文件,位子\inc\inc.php

代码:

function top_comments($number = 98) {
	global $wpdb;
	$counts = wp_cache_get( 'mostactive' );
	if ( false === $counts ) {
		$counts = $wpdb->get_results("SELECT COUNT(comment_author) AS cnt, comment_author, comment_author_url, comment_author_email
		FROM {$wpdb->prefix}comments
		WHERE comment_date > date_sub( NOW(), INTERVAL 90 DAY )
		AND comment_approved = '1'
		AND comment_author_email != 'example@example.com'
		AND comment_author_email != ''
		AND comment_type = ''
		AND user_id = '0'
		GROUP BY comment_author_email
		ORDER BY cnt DESC
		LIMIT $number");
	}
	$mostactive =  '<div class="top-comments">';
	if ( $counts ) {
		wp_cache_set( 'mostactive', $counts );
		foreach ($counts as $count) {
			$c_url = $count->comment_author_url;
			$mostactive .= '
			<div class="lx8">
				<div class="top-author">
					<div class="top-comment"><a href="' . get_template_directory_uri()."/inc/go.php?url=". $c_url . '" target="_blank" rel="external nofollow">' . get_avatar($count->comment_author_email, 96). '<div class="author-url"><strong> ' . $count->comment_author . '</div></strong></a></div>
					<div class="top-comment">'.$count->cnt.'个脚印</div>
				</div>
			</div>';
		}
		$mostactive .= '<div class="clear"></div></div>';
		echo $mostactive;
	}
}
if (zm_get_option('meta_delete')) {
} else {
require get_template_directory() . '/inc/meta-delete.php';
}

begin主题最近读者源码解析

上图我标出来是主要条件,比如我为了让我的最近读者显示更人性化,我就只删掉了URL网站一个条件。关于其他的条件可以根据我截图的SQL代码进行修改的。

 

 

 

 

 

历史上的今天:


欢迎来到菜鸟头头的个人博客
本文章百度已收录,若发现本站有任何侵犯您利益的内容,请及时邮件或留言联系,我会第一时间删除所有相关内容。

  • A+
所属分类:WEB

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

目前评论:6   其中:访客  4   博主  2

    • avatar iMJMJ 4

      学习一下~~~~支持顶起

      • avatar 请输入您的QQ号 1

        我安装begin主题后出现如下错误,
        Fatal error: Cannot redeclare wpse_11826_search_by_title() (previously declared in /www/wwwroot/域名/wp-content/plugins/fengrui-xingshu/fengrui-xingshu.php:39) in /www/wwwroot/域名/wp-content/themes/begin5.2/inc/inc.php on line 16

        关闭星宿UI多端小程序插件后报错
        Warning: Use of undefined constant taotag – assumed ‘taotag’ (this will throw an Error in a future version of PHP) in /www/wwwroot/域名/wp-content/themes/begin5.2/inc/post-type.php on line 374

        请问这个怎么解决

          • avatar 头头 Admin

            @请输入您的QQ号 你某个插件引起了冲突

              • avatar 863576356 1

                @头头 是的我把星宿Ui插件关闭了,然后php 关闭了错误警告,可以用了

                  • avatar 头头 Admin

                    @863576356 一般这样情况,就不用这个插件。

                      • avatar 请输入您的QQ号 1

                        @头头 好的,感谢回复