请教article区块:可否显示分类的「描述」文字? [技术论坛 - Article] imag1

正在浏览:   1 名游客






请教article区块:可否显示分类的「描述」文字?
中级会员
注册日期:
2007/11/2 2:00
所属群组:
注册会员
帖子: 42 | 精华: 2
等级: 5; EXP: 27
HP: 0 / 106
MP: 14 / 79
离线
如题
article最新消息区块可以显示各文章分类的标题
但是否有办法将各分类的「描述」文字也显示出来?

试过将<$category.description}>变量放进article_block_news.html样板里
但是似乎完全没有作用

请各位先进指导
非常感谢

12/1 1:55
工具箱 短消息 Email PDF 书签 打印 举报 回顶部


回复: 请教article最新消息区块所显示的文章分类标题,可否让分类的「描述」文字也显示出来?
资深会员
注册日期:
2006/11/30 20:48
来自 pekin
所属群组:
注册会员
Dev+Hack
帖子: 219 | 精华: 6
等级: 13; EXP: 82
HP: 64 / 320
MP: 73 / 1099
离线
引文:

Mori 写道:
如题
article最新消息区块可以显示各文章分类的标题
但是否有办法将各分类的「描述」文字也显示出来?

试过将<$category.description}>变量放进article_block_news.html样板里
但是似乎完全没有作用

请各位先进指导
非常感谢

模板只是版式和样式的调整,具体显示什么内容要看该模块下blocks文件夹中相应的文件,这个文件控制该区块都显示什么内容,并且对其内容的现实形式进行设置。
所以,如果想显示出区块模板中未给出的数据请检查这个文件。

至于你这个问题我小hack了一下,没有进行太多测试。

1.找到article/blocks/blocks_news.php
打开此文件找到以下代码:

/**#@+
 * Function to display news item: spotlight + recent news
 *
 * {@link spotlight} 
 * {@link config} 
 *
 * @param    array     $options:  
 *                        0 - display mode: 0 - compact title list; 1 sorted by categories 
 *                        1 - limit for article count; 
 *                        2 - title length; 
 *                        3 - time format; 
 *                        4 - allowed categories; 
 */
function [VAR_PREFIX]_block_news_show$options )
{
    global 
$xoopsDB;
    static 
$access_cats;
    
$block = array();
    
    if(!isset(
$access_cats)){
        
$permission_handler =& xoops_getmodulehandler("permission"$GLOBALS["artdirname"]);
        
$access_cats $permission_handler->getCategories("access");
    }
    if (!empty(
$options[4])) {
        
$allowed_cats array_filter(array_slice($options4));
    }else{
        
$allowed_cats $access_cats;
    }
    
$allowed_cats array_intersect($allowed_cats$access_cats);
    
    if( 
count($allowed_cats) ==) {
        return 
$block;
    }
    
    
mod_loadFunctions("url"$GLOBALS["artdirname"]);
    
    
$spotlight_handler =& xoops_getmodulehandler("spotlight"$GLOBALS["artdirname"]);
    
$sp_data $spotlight_handler->getContent(false);
    foreach(
$sp_data as $key => $val){
        
$block["spotlight"][$key] = $val;
    }
    
$block["spotlight"]["url"] = art_buildUrl(XOOPS_URL."/modules/".$GLOBALS["artdirname"]."/view.article.php", array("article" => $block["spotlight"]["art_id"]));
    
    
mod_loadFunctions("author"$GLOBALS["artdirname"]);
    
$users art_getAuthorNameFromId($sp_data["uid"], truetrue);
    
$block["spotlight"]["author"] = $users[$sp_data["uid"]] ;
    if(!empty(
$sp_data["writer_id"])) {
        
$writers art_getWriterNameFromIds($sp_data["writer_id"]);
        
$block["spotlight"]["writer"] = $writers[$sp_data["writer_id"]] ;
    }
    
    
$category_handler =& xoops_getmodulehandler("category"$GLOBALS["artdirname"]);
    
    if(empty(
$options[0])):
    
    
$sql =     "    SELECT art_id, art_title, art_time_publish, cat_id, ( art_comments + art_trackbacks ) AS comments ".
            
"    FROM " art_DB_prefix("article").
            
"    WHERE cat_id IN (" implode(","$allowed_cats) . ") ".
            
"        AND art_time_publish >0 ".
            
"    ORDER BY art_time_publish DESC";
    if (!
$result $xoopsDB->query($sql$options[1], 0)) {
        
//xoops_error($xoopsDB->error());
        
return $block;
    }
    
    
mod_loadFunctions("time"$GLOBALS["artdirname"]);
    
$articles = array();
    
$cids = array();
    while (
$row $xoopsDB->fetchArray($result)) {
        
$_art = array();
        
$_art["title_full"]    = htmlspecialchars($row["art_title"]);
        
$_art["title"]        = $row["art_title"];
        
$_art["time"]        = art_formatTimestamp($row["art_time_publish"], $options[3]);
        
$_art["comments"]    = $row["comments"];
        
$_art["category"]    = $row["cat_id"];
        
$_art["url"]         = art_buildUrl(XOOPS_URL."/modules/".$GLOBALS["artdirname"]."/view.article.php", array("article" => $row["art_id"]));
        
        
$articles[$row["art_id"]] = $_art;
        
$cids[$row["cat_id"]] = 1;
    }
    
    
$criteria = new CriteriaCompo( new Criteria("cat_id""(".implode(","array_keys($cids)).")""IN") );
    
$criteria_top = new CriteriaCompo( new Criteria("cat_id""(".implode(","$allowed_cats).")""IN") ); 
    
$criteria_top->add( new Criteria("cat_pid"0) );
    
$criteria->add$criteria_top"OR" );
    
$criteria->setSort("cat_order");
    
$categories_obj $category_handler->getAll($criteria, array("cat_title""cat_pid"));

    foreach(
array_keys($articles) as $id){
        
$articles[$id]["title"] = "[".$categories_obj[$articles[$id]["category"]]->getVar("cat_title""n")."] ".$articles[$id]["title"];
        if(!empty(
$options[2])){
            
$articles[$id]["title"] = xoops_substr($articles[$id]["title"], 0$options[2]);
        }
        
$articles[$id]["title"] = htmlspecialchars($articles[$id]["title"]);
    }
    
    
$categories = array();
    foreach(
array_keys($categories_obj) as $cid) {
        if(
$categories_obj[$cid]->getVar("cat_pid")) continue;
        
$categories[$cid]["title"]    = $categories_obj[$cid]->getVar("cat_title");
        
$categories[$cid]["url"]    = art_buildUrl(XOOPS_URL."/modules/".$GLOBALS["artdirname"]."/view.category.php", array("category" => $cid));
    }
    
$block["articles"] = $articles;
    
$block["categories"] = $categories;
    
    else:
    
    
$articles_id = array();
    
$criteria = new Criteria("cat_id""(".implode(","$allowed_cats).")""IN");
    
$criteria->setSort("cat_order");
    
$categories_obj $category_handler->getAll($criteria, array("cat_title""cat_lastarticles"));
    
    foreach(
array_keys($categories_obj) as $id){
        if(!
$articles_category $category_handler->getLastArticleIds($categories_obj[$id], $options[1])) continue;
        
$articles_id array_merge($articles_id$articles_category);
    }
    
    if( 
count($articles_id) ==) {
        return 
$block;
    }
    
    
$sql =     "    SELECT art_id, art_title, art_time_publish, ( art_comments + art_trackbacks ) AS comments ".
            
"    FROM " art_DB_prefix("article").
            
"    WHERE art_id IN (" implode(","array_unique($articles_id)) . ") ";
    if (!
$result $xoopsDB->query($sql)) {
        
//xoops_error($xoopsDB->error());
        
return $block;
    }
    
    
$articles = array();
    while (
$row $xoopsDB->fetchArray($result)) {
        
$_art = array();
        
$_art["title_full"]    = htmlspecialchars($row["art_title"]);
        if(!empty(
$options[2])){
            
$row["art_title"] = xoops_substr($row["art_title"], 0$options[2]);
        }
        
$_art["title"]        = htmlspecialchars($row["art_title"]);
        
$_art["time"]        = art_formatTimestamp($row["art_time_publish"], $options[3]);
        
$_art["comments"]    = $row["comments"];
        
$_art["url"]         = art_buildUrl(XOOPS_URL."/modules/".$GLOBALS["artdirname"]."/view.article.php", array("article" => $row["art_id"]));
        
$articles[$row["art_id"]] = $_art;
    }
    
    
$categories = array();
    foreach(
array_keys($categories_obj) as $id){
        
$category =& $categories_obj[$id];
        
$cat = array(
            
"id"                 => $id,
            
"title"             => $category->getVar("cat_title"),
            
"image"             => $category->getImage(),
            
"url"                 => art_buildUrl(XOOPS_URL."/modules/".$GLOBALS["artdirname"]."/view.category.php", array("category" => $id)),
            
"articles"            => array(),
        );
        
$articles_category_id $category_handler->getLastArticleIds($category$options[1]);
        foreach(
$articles_category_id as $art_id){
            if(!isset(
$articles[$art_id])) continue;
            
$cat["articles"][] =& $articles[$art_id];
        }
        
$categories[$id] = $cat;
        unset(
$cat);
    }
    
$block["categories"] =& $categories;
    
    endif;
        
    
$block["lang"]         = array(
                                
"categories"    => art_constant("MB_CATEGORIES"), 
                                
"articles"        => art_constant("MB_ARTICLES"),
                                
"comments"        => art_constant("MB_COMMENTS"),
                                
"views"            => art_constant("MB_VIEWS"),
                                );
    
$block["mode"]         = $options[0];
    
$block["dirname"]    = $GLOBALS["artdirname"];
    return 
$block;
}

用以下代码替换:

/**#@+
 * Function to display news item: spotlight + recent news
 *
 * {@link spotlight} 
 * {@link config} 
 *
 * @param    array     $options:  
 *                        0 - display mode: 0 - compact title list; 1 sorted by categories 
 *                        1 - limit for article count; 
 *                        2 - title length; 
 *                        3 - time format; 
 *                        4 - allowed categories; 
 */
function [VAR_PREFIX]_block_news_show$options )
{
    global 
$xoopsDB;
    static 
$access_cats;
    
$block = array();
    
    if(!isset(
$access_cats)){
        
$permission_handler =& xoops_getmodulehandler("permission"$GLOBALS["artdirname"]);
        
$access_cats $permission_handler->getCategories("access");
    }
    if (!empty(
$options[4])) {
        
$allowed_cats array_filter(array_slice($options4));
    }else{
        
$allowed_cats $access_cats;
    }
    
$allowed_cats array_intersect($allowed_cats$access_cats);
    
    if( 
count($allowed_cats) ==) {
        return 
$block;
    }
    
    
mod_loadFunctions("url"$GLOBALS["artdirname"]);
    
    
$spotlight_handler =& xoops_getmodulehandler("spotlight"$GLOBALS["artdirname"]);
    
$sp_data $spotlight_handler->getContent(false);
    foreach(
$sp_data as $key => $val){
        
$block["spotlight"][$key] = $val;
    }
    
$block["spotlight"]["url"] = art_buildUrl(XOOPS_URL."/modules/".$GLOBALS["artdirname"]."/view.article.php", array("article" => $block["spotlight"]["art_id"]));
    
    
mod_loadFunctions("author"$GLOBALS["artdirname"]);
    
$users art_getAuthorNameFromId($sp_data["uid"], truetrue);
    
$block["spotlight"]["author"] = $users[$sp_data["uid"]] ;
    if(!empty(
$sp_data["writer_id"])) {
        
$writers art_getWriterNameFromIds($sp_data["writer_id"]);
        
$block["spotlight"]["writer"] = $writers[$sp_data["writer_id"]] ;
    }
    
    
$category_handler =& xoops_getmodulehandler("category"$GLOBALS["artdirname"]);
    
    if(empty(
$options[0])):
    
    
$sql =     "    SELECT art_id, art_title, art_time_publish, cat_id, ( art_comments + art_trackbacks ) AS comments ".
            
"    FROM " art_DB_prefix("article").
            
"    WHERE cat_id IN (" implode(","$allowed_cats) . ") ".
            
"        AND art_time_publish >0 ".
            
"    ORDER BY art_time_publish DESC";
    if (!
$result $xoopsDB->query($sql$options[1], 0)) {
        
//xoops_error($xoopsDB->error());
        
return $block;
    }
    
    
mod_loadFunctions("time"$GLOBALS["artdirname"]);
    
$articles = array();
    
$cids = array();
    while (
$row $xoopsDB->fetchArray($result)) {
        
$_art = array();
        
$_art["title_full"]    = htmlspecialchars($row["art_title"]);
        
$_art["title"]        = $row["art_title"];
        
$_art["time"]        = art_formatTimestamp($row["art_time_publish"], $options[3]);
        
$_art["comments"]    = $row["comments"];
        
$_art["category"]    = $row["cat_id"];
        
$_art["url"]         = art_buildUrl(XOOPS_URL."/modules/".$GLOBALS["artdirname"]."/view.article.php", array("article" => $row["art_id"]));
        
        
$articles[$row["art_id"]] = $_art;
        
$cids[$row["cat_id"]] = 1;
    }
    
    
$criteria = new CriteriaCompo( new Criteria("cat_id""(".implode(","array_keys($cids)).")""IN") );
    
$criteria_top = new CriteriaCompo( new Criteria("cat_id""(".implode(","$allowed_cats).")""IN") ); 
    
$criteria_top->add( new Criteria("cat_pid"0) );
    
$criteria->add$criteria_top"OR" );
    
$criteria->setSort("cat_order");
    
//ezsky hack add array obj cat_description
    
$categories_obj $category_handler->getAll($criteria, array("cat_title""cat_pid""cat_description"));

    foreach(
array_keys($articles) as $id){
        
$articles[$id]["title"] = "[".$categories_obj[$articles[$id]["category"]]->getVar("cat_title""n")."] ".$articles[$id]["title"];
        if(!empty(
$options[2])){
            
$articles[$id]["title"] = xoops_substr($articles[$id]["title"], 0$options[2]);
        }
        
$articles[$id]["title"] = htmlspecialchars($articles[$id]["title"]);
    }
    
    
$categories = array();
    foreach(
array_keys($categories_obj) as $cid) {
        if(
$categories_obj[$cid]->getVar("cat_pid")) continue;
        
$categories[$cid]["title"]    = $categories_obj[$cid]->getVar("cat_title");
        
//ezsky hack
        
$categories[$cid]["description"]    = $categories_obj[$cid]->getVar("cat_description");
        
        
$categories[$cid]["url"]    = art_buildUrl(XOOPS_URL."/modules/".$GLOBALS["artdirname"]."/view.category.php", array("category" => $cid));
    }
    
$block["articles"] = $articles;
    
$block["categories"] = $categories;
    
    else:
    
    
$articles_id = array();
    
$criteria = new Criteria("cat_id""(".implode(","$allowed_cats).")""IN");
    
$criteria->setSort("cat_order");
    
    
//ezsky hack add array obj cat_description
    
$categories_obj $category_handler->getAll($criteria, array("cat_title""cat_lastarticles""cat_description"));
    
    foreach(
array_keys($categories_obj) as $id){
        if(!
$articles_category $category_handler->getLastArticleIds($categories_obj[$id], $options[1])) continue;
        
$articles_id array_merge($articles_id$articles_category);
    }
    
    if( 
count($articles_id) ==) {
        return 
$block;
    }
    
    
$sql =     "    SELECT art_id, art_title, art_time_publish, ( art_comments + art_trackbacks ) AS comments ".
            
"    FROM " art_DB_prefix("article").
            
"    WHERE art_id IN (" implode(","array_unique($articles_id)) . ") ";
    if (!
$result $xoopsDB->query($sql)) {
        
//xoops_error($xoopsDB->error());
        
return $block;
    }
    
    
$articles = array();
    while (
$row $xoopsDB->fetchArray($result)) {
        
$_art = array();
        
$_art["title_full"]    = htmlspecialchars($row["art_title"]);
        if(!empty(
$options[2])){
            
$row["art_title"] = xoops_substr($row["art_title"], 0$options[2]);
        }
        
$_art["title"]        = htmlspecialchars($row["art_title"]);
        
$_art["time"]        = art_formatTimestamp($row["art_time_publish"], $options[3]);
        
$_art["comments"]    = $row["comments"];
        
$_art["url"]         = art_buildUrl(XOOPS_URL."/modules/".$GLOBALS["artdirname"]."/view.article.php", array("article" => $row["art_id"]));
        
$articles[$row["art_id"]] = $_art;
    }
    
    
$categories = array();
    foreach(
array_keys($categories_obj) as $id){
        
$category =& $categories_obj[$id];
        
$cat = array(
            
"id"                 => $id,
            
"title"             => $category->getVar("cat_title"),
            
//ezsky hack
        
"description"    => $category->getVar("cat_description"),
            
"image"             => $category->getImage(),
            
"url"                 => art_buildUrl(XOOPS_URL."/modules/".$GLOBALS["artdirname"]."/view.category.php", array("category" => $id)),
            
"articles"            => array(),
        );
        
$articles_category_id $category_handler->getLastArticleIds($category$options[1]);
        foreach(
$articles_category_id as $art_id){
            if(!isset(
$articles[$art_id])) continue;
            
$cat["articles"][] =& $articles[$art_id];
        }
        
$categories[$id] = $cat;
        unset(
$cat);
    }
    
$block["categories"] =& $categories;
    
    endif;
        
    
$block["lang"]         = array(
                                
"categories"    => art_constant("MB_CATEGORIES"), 
                                
"articles"        => art_constant("MB_ARTICLES"),
                                
"comments"        => art_constant("MB_COMMENTS"),
                                
"views"            => art_constant("MB_VIEWS"),
                                );
    
$block["mode"]         = $options[0];
    
$block["dirname"]    = $GLOBALS["artdirname"];
    return 
$block;
}


2.在最新消息的模板文件(article_block_news.html)中的相应位置上添加显示标签

<{$category.description}>

12/1 4:55
_________________
哦的小站,发点牢骚。http://ez.xoops.cn欢迎大家踩踩。
工具箱 短消息 Email PDF 书签 打印 举报 回顶部


回复: 请教article最新消息区块所显示的文章分类标题,可否让分类的「描述」文字也显示出来?
中级会员
注册日期:
2007/11/2 2:00
所属群组:
注册会员
帖子: 42 | 精华: 2
等级: 5; EXP: 27
HP: 0 / 106
MP: 14 / 79
离线
唔,原来如此

小弟是新手
非常感谢先进的指导
赶紧来试用看看

12/1 9:41
工具箱 短消息 Email PDF 书签 打印 举报 回顶部





可以查看帖子。
不可发帖。
不可回复。
不可编辑自己的帖子。
不可删除自己的帖子。
不可发起投票调查。
不可在投票调查中投票。
不可上传附件。
不可不经审核直接发帖。
不可使用主题类别。
不可以使用HTML语法。
不可以使用签名档。

[高级搜索]