通过摸索,笔者请mzsongyan兄弟为大家写下了在emlog顶级列表页下调用二级栏目标题及文章内容的方法,实现效果如下图所示:
这个方法是mzsongyan兄弟无私奉献出来的,所以笔者不敢私藏,也从来没有私藏的意思,一方面是为了彰显分享的初衷,另一方面是为了让更多的人享受mzsongyan兄弟为大家带来的牛气代码。好了,废话太多,相关代码如下:
一、放置在modul.php中的代码模块:
<?PHP function is_sub_category($pid){ $db = Database::getInstance(); $sql = "SELECT sid,sortname FROM " . DB_PREFIX . "sort WHERE pid = $pid"; $res = $db->query($sql); $num = $db->num_rows($res); return $num; } function get_sub_category_post($pid, $num = 10){ $db = Database::getInstance(); $sql = "SELECT sid,sortname FROM " . DB_PREFIX . "sort WHERE pid = $pid"; $res = $db->query($sql); while ($row = $db->fetch_array($res)) { echo "<h2><a href='" . Url::sort($row['sid']) . "'>" . $row['sortname'] . "</a></h2>"; get_post_list($row['sid'], $num); } } function get_post_list($sid, $num = 10){ $db = Database::getInstance(); $sql = "SELECT gid,title FROM " . DB_PREFIX . "blog WHERE sortid = $sid and type = 'blog' and hide = 'n' and password = '' LIMIT 0 , $num"; $res = $db->query($sql); echo '<ul>'; while ($row = $db->fetch_array($res)){ echo "<li><a href='" . Url::log($row['gid']) . "'>" . $row['title'] . "</a></li>"; } echo '</ul>'; } ?>
二、在log_list.php中将如下代码放置在内容区域,是替换掉原来模板中的代码。如下:
<?php $abc = false; if(! empty($sortid)){ $abc = is_sub_category($sortid) > 0 ? false : true; } if(blog_tool_ishome() OR $abc): if (!empty($logs)): foreach($logs as $value): ?> <h2><?php topflg($value['top'], $value['sortop'], isset($sortid)?$sortid:''); ?><a href="<?php echo $value['log_url']; ?>"><?php echo $value['log_title']; ?></a></h2> <p class="date"><?php echo gmdate('Y-n-j', $value['date']); ?> <?php blog_author($value['author']); ?> <?php blog_sort($value['logid']); ?> <?php editflg($value['logid'],$value['author']); ?> </p> <?php echo $value['log_description']; ?> <p class="tag"><?php blog_tag($value['logid']); ?></p> <p class="count"> <a href="<?php echo $value['log_url']; ?>#comments">评论(<?php echo $value['comnum']; ?>)</a> <a href="<?php echo $value['log_url']; ?>">浏览(<?php echo $value['views']; ?>)</a> </p> <div style="clear:both;"></div> <?php endforeach;else:?> <h2>未找到</h2> <p>抱歉,没有符合您查询条件的结果。</p> <?php endif;?> <div id="pagenavi"><?php echo $page_url;?></div> <?php else: ?> <?php get_sub_category_post($sortid); ?> <?php endif; ?>
原文标题:让emlog列表页比众CMS更加牛气的方法(http://www.liangxin.name/?post=598)
有朋自远方来...评论一下呗O(∩_∩)O