$query = DB::query("SELECT a.aid,a.title
FROM ".DB::table('portal_article_related')." r
LEFT JOIN ".DB::table('portal_article_title')." a ON a.aid=r.raid
WHERE r.aid='$aid' ORDER BY r.displayorder");
把它修改成
$query = DB::query("SELECT aid,title
FROM ".DB::table('portal_article_title')." where catid='$article[catid]' order by rand() limit 10");
就行了,这样打开文章页面时最下面的相关阅读回随机显示10条本类的文章。是随机显示,每次都会改变。相关阅读可以增加内链,对收录和SEO有好处。
$query = DB::query("SELECT a.aid,a.title
FROM ".DB::table('portal_article_related')." r
LEFT JOIN ".DB::table('portal_article_title')." a ON a.aid=r.raid
WHERE r.aid='$aid' ORDER BY r.displayorder");
在上面代码添加下面代码
/*新增随机内容*/
$article['randomrelated'] = array();
$query = DB::query("SELECT aid,title
FROM ".DB::table('portal_article_title')." where catid='$article[catid]' order by rand() limit 12");
while ($value = DB::fetch($query)) {
$article['randomrelated'][] = $value;
}
/*新增相关内容*/
$article['relatedcontent'] = array();
$query = DB::query("SELECT a.aid,a.title
FROM ".DB::table('portal_article_related')." r
LEFT JOIN ".DB::table('portal_article_title')." a ON a.aid=r.raid
where catid='$article[catid]' order by rand() limit 12");
while ($value = DB::fetch($query)) {
$article['relatedcontent'][] = $value;
}