内容页TAG相关文章优化

well2022-03-02  882

今天有个wellcms学者遇见的一个小问题,内容页模板增加tag相关文章代码,当文章没有TAG时会出现一串错误代码。

<?php if ($thread['tag']) {
    $tagids = array_keys($thread['tag_fmt']);
    $arrlist = well_tag_thread_find($tagids, 1, 100);
    !$arrlist and $arrlist = well_tag_thread__find(array(), array('id' => 1), 1, 100);

    if ($arrlist) {
        $count = count($arrlist);
        $total = $count > $pagesize ? $pagesize : $count;
        $tidarr = $count > 20 ? array_rand($arrlist, $total) : array_keys($arrlist);

        $arrlist = well_thread_find_asc($tidarr, $total);
    }
}
?>
<!-- 判断是否有相关主题 开始 -->
【加】<?php if ($thread['tag']) { ?>
<?php if (!empty($arrlist)) { ?>
<div class="card border-0 shadow-sm mb-3">
	<div class="card-header bg-white">
		<h3 class="h6 font-weight-400 my-0">
			猜你喜欢
		</h3>
	</div>
	<ul class="list-group list-group-flush">
		<!-- 循环输出相关主题 开始 -->
		<?php foreach($arrlist as $val) { ?>
		<li class="list-group-item bg-white">
			<h4 class="h6 my-0">
				<a href="<?php echo $val['url'];?>" class="d-block text-truncate">
					<?php echo $val['subject'];?>
				</a>
			</h4>
		</li>
		<?php } ?>

		<!-- 循环输出相关主题 结束 -->
	</ul>
</div>
<?php } ?>
【加】<?php } ?>

自从有了tag内容页很丰富

转载请注明原文地址:https://www.wellcms.net/read-191.html
01
最新回复(2)