[Hack]Xoops中article模块分类显示页面同时显示子分类文章的方法

D.J.老大的article模组确实好用,但是在分类文章列表显示页面view.category.php这个文件中却只显示给定栏目ID的文章和子分类列表及子分类文章数。虽然个人比较喜欢这种方式,但这种方式并不适合目前国内流行文章管理系统在显示栏目的文章方式,一般的网站在现实栏目时需要将分类的子分类文章也同时显示出来。

针对目前大多数都是采用两级分类的方式,我对view.category.php做了一些Hack:

1、在view.category.php 97行附近修改如下:

$counts_category =& $category_handler->getCategoryCounts(array_keys($categories), "access");
    //Add By XuYong 获取子栏目下给定篇数文章

    $articles_perpage = (empty($start) && empty($list)) ? $xoopsModuleConfig["articles_category"] : $xoopsModuleConfig["articles_perpage"];
    //End Add

foreach( $categories as $id=>$cat){
    //Add By XuYong 获取子栏目下给定篇数文章
    $subcriteria = new CriteriaCompo(new Criteria("ac.ac_publish", 0, ">"));
    $subarticle_id =& $article_handler->getIdsByCategory($cat, $articles_perpage, 0, $subcriteria);
    if(count($subarticle_id)>0){
        $criteria = new Criteria("art_id", "(".implode(",",$subarticle_id).")", "IN");
        $tags = array("uid", "writer_id", "art_title", "art_summary", "art_image", "art_pages", "art_categories", "art_time_publish", "art_counter", "art_comments", "art_trackbacks");
        $subarticles_obj =& $article_handler->getAll($criteria, $tags);
    }else{
        $subarticles_obj = array();
    }

    $subcatarticles = array();
    foreach ($subarticle_id as $id) {
        $_article = array(
            "id"        => $id,
            "title"        => $subarticles_obj[$id]->getVar("art_title"),
            "time"        => $subarticles_obj[$id]->getTime($xoopsModuleConfig["timeformat"]),
            "image"        => $subarticles_obj[$id]->getImage(),
            "counter"    => $subarticles_obj[$id]->getVar("art_counter"),
            "comments"    => $subarticles_obj[$id]->getVar("art_comments"),
            "trackbacks"=> $subarticles_obj[$id]->getVar("art_trackbacks")
            );
        if(!empty($xoopsModuleConfig["display_summary"])){
            $_article["summary"] = $subarticles_obj[$id]->getSummary(true);
        }
        $subcatarticles[$id] = $_article;
        unset($_article);
    }

    //End Add
    $subcategories[] = array(
        "id"            => $cat->getVar("cat_id"),
        "title"            => $cat->getVar("cat_title"),
        "articles"        => @intval($counts_article[$cat->getVar("cat_id")]),
        "categories"    => @intval($counts_category[$cat->getVar("cat_id")]),
        "subcatart"  => $subcatarticles
        );
        //Add By XuYong 获取子栏目下给定篇数文章
        unset($subcatarticles);
        //End Add
}
unset($criteria);
$criteria = new CriteriaCompo(new Criteria("ac.ac_feature", 0, ">"));
$criteria->setSort("ac.ac_feature");

2、修改模板文件article_category.html文件,134行附近修改如下:

<{if count($categories) gt 0}>
<div id="category" class="article-category">

    <{foreachq item=cat name=cat from=$categories}>
    <div class="category-header tdbg4" stype="width:80%">
<span class="sizscolor"><b><a href="<{$xoops_url}>/modules/<{$xoops_dirname}>/view.category.php<{$smarty.const.URL_DELIMITER}>c<{$cat.id}>/list"><{$cat.title}></a></b></span>
    </div>

        <{if count($cat.subcatart) gt 0}>
        <div id="article_<{$cat.id}>" class="article-article">
                    <table width="95%" border="0" align="center" cellspacing="0">
                        <{foreachq item=article from=$cat.subcatart}>
                      <tr class="tdlist">
                        <td  width="86%" height="24" class="tdlist">·<a href="<{$xoops_url}>/modules/<{$xoops_dirname}>/view.article.php<{$smarty.const.URL_DELIMITER}><{$article.id}>"><{$article.title}></a>
                                        <{if $article.image}><img src="<{$xoops_url}>/modules/<{$xoops_dirname}>/images/image.gif" width="12px" alt="" /><{/if}>
                        </td>
                        <td width="14%" height="2" class="tdlist"><{$article.time|date_format:"%y-%d-%m"}></td>
                      </tr>
                      <{/foreach}>
                                </table>
        </div>
        <{/if}>
            <div class="article-section-title">
            <span class="subject"> </span>
            <span class="navigation"><a href="<{$xoops_url}>/modules/<{$xoops_dirname}>/view.category.php<{$smarty.const.URL_DELIMITER}>c<{$cat.id}>/list"><{$smarty.const._MORE}></a>
            </span>
            </div>
            <div class="clear"></div>
    <{/foreach}>

</div>
<{/if}>

其中有些样式和一些修改是根据当前需要改的,需要根据自身情况调整。

效果demo;

view_category_hack_demo

 

Hack后的iview.category.php和模板文件下载: