发新话题
打印

[模块] 修改 Latestnews模块,改进显示效果

修改 Latestnews模块,改进显示效果

根据http://forum.mamboserver.com/archive/index.php/t-53156.html和 Latestnews modified模块修改而成,可以使条目的颜色交替显示,显示文章的创建时间,显示“更多”链接(链接到catagory),指定itemid来使用 menu 对应的模板。

首先修改的是xml文件,增加了几个变量:
引用:
<?xml version="1.0" encoding="iso-8859-1"?>
<mosinstall type="module" version="4.5.2">
        <name>Latest News MODIFIED</name>
        <author>Maximilian Ebert</author>
        <creationDate>September 2005</creationDate>
        <copyright>Maximilian Ebert</copyright>
        <license>http://www.gnu.org/copyleft/gpl.html GNU/GPL</license>
        <authorEmail>max.ebert@titoly.de</authorEmail>
        <authorUrl>www.joomla-clantools.com</authorUrl>
        <version>1.0</version>
        <description>显示最新文章模块,显示文章的创建时间,可以设置颜色交替显示,可以根据菜单设置模板</description>
        <files>
                <filename module="mod_latestnews-modified">mod_latestnews-modified.php</filename>
        </files>
        <params>
                <param name="moduleclass_sfx" type="text" default="" label="Module Class Suffix" description="A suffix to be applied to the css class of the module (table.moduletable), this allows individual module styling" />
                <param name="@spacer" type="spacer" default="" label="" description="" />
                <param name="cache" type="radio" default="0" label="Enable Cache" description="Select whether to cache the content of this module">
                        <option value="0">No</option>
                        <option value="1">Yes</option>
                </param>
                <param name="@spacer" type="spacer" default="" label="" description="" />
                <param name="type" type="list" default="0" label="Module Mode" description="Allows you to control which type of Content to display in the module">
                        <option value="1">Content Items only</option>
                        <option value="2">Static Content only</option>
                        <option value="3">Both</option>
                </param>
                <param name="@spacer" type="spacer" default="" label="" description="" />
                <param name="show_front" type="radio" default="1" label="Frontpage Items" description="Show/Hide items designated for the Frontpage - only works when in Content Items only mode">
                        <option value="1">show</option>
                        <option value="0">hide</option>
                </param>
                <param name="@spacer" type="spacer" default="" label="" description="" />
                <param name="show_time" type="radio" default="0" label="Time" description="Show/Hide Time when created the News">
                        <option value="1">show</option>
                        <option value="0">hide</option>
                </param>
                <param name="count" type="text" default="5" label="Count" description="The number of items to display (default 5)" />
                <param name="catid" type="text" default="" label="Category ID" description="Selects items from a specific Category or set of Categories (to specify more than one Category, seperate with a comma , )." />
                <param name="secid" type="text" default="" label="Section ID" description="Selects items from a specific Secion or set of Sections (to specify more than one Section, seperate with a comma , )." />
                <param name="menu_itemid" type="text" default="" label="menu_itemid" description="指定以哪个菜单所对应的模板显示 )." />

        </params>
</mosinstall>
然后是php文件:
引用:
<?php
/**
* @version $Id: mod_latestnews.php,v 1.7 2005/01/23 17:19:53 levis Exp $
* @package Mambo
* @copyright (C) 2000 - 2005 Miro International Pty Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* Mambo is Free Software
*/

/** ensure this file is being included by a parent file */
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

global $mosConfig_offset, $mosConfig_live_site, $mainframe;

$type                 = intval( $params->get( 'type', 1 ) );
$count                 = intval( $params->get( 'count', 5 ) );
$catid                 = trim( $params->get( 'catid' ) );
$secid                 = trim( $params->get( 'secid' ) );
$menu_itemid        = trim( $params->get( 'menu_itemid'  ) );
$show_front        = $params->get( 'show_front', 1 );
$show_time        = $params->get( 'show_time', 1 );
$class_sfx        = $params->get( 'moduleclass_sfx' );

$now                 = date( 'Y-m-d H:i:s', time() + $mosConfig_offset * 60 * 60 );

$access = !$mainframe->getCfg( 'shownoauth' );

// select between Content Items, Static Content or both
switch ( $type ) {
        case 2: //Static Content only
                $query = "SELECT a.id, a.title"
                . "\n FROM #__content AS a"
                . "\n WHERE ( a.state = '1' AND a.checked_out = '0' AND a.sectionid = '0' )"
                . "\n AND ( a.publish_up = '0000-00-00 00:00:00' OR a.publish_up <= '". $now ."' )"
                . "\n AND ( a.publish_down = '0000-00-00 00:00:00' OR a.publish_down >= '". $now ."' )"
            . ( $access ? "\n AND a.access <= '". $my->gid ."'" : '' )
                . "\n ORDER BY a.created DESC LIMIT $count"
                ;
                $database->setQuery( $query );
                $rows = $database->loadObjectList();       
                break;

        case 3: //Both
                $query = "SELECT a.id, a.title, a.sectionid"
                . "\n FROM #__content AS a"
                . "\n WHERE ( a.state = '1' AND a.checked_out = '0' )"
                . "\n AND ( a.publish_up = '0000-00-00 00:00:00' OR a.publish_up <= '". $now ."' )"
                . "\n AND ( a.publish_down = '0000-00-00 00:00:00' OR a.publish_down >= '". $now ."' )"
            . ( $access ? "\n AND a.access <= '". $my->gid ."'" : '' )
                . "\n ORDER BY a.created DESC LIMIT $count"
                ;
                $database->setQuery( $query );
                $rows = $database->loadObjectList();       
                break;
               
        case 1:  //Content Items only
        default:
                $query = "SELECT a.id, a.title, a.created, a.sectionid, a.catid"
                . "\n FROM #__content AS a"
                . "\n LEFT JOIN #__content_frontpage AS f ON f.content_id = a.id"
                . "\n WHERE ( a.state = '1' AND a.checked_out = '0' AND a.sectionid > '0' )"
                . "\n AND ( a.publish_up = '0000-00-00 00:00:00' OR a.publish_up <= '". $now ."' )"
                . "\n AND ( a.publish_down = '0000-00-00 00:00:00' OR a.publish_down >= '". $now ."' )"
            . ( $access ? "\n AND a.access <= '". $my->gid ."'" : '' )
                . ( $catid ? "\n AND ( a.catid IN (". $catid .") )" : '' )
                . ( $secid ? "\n AND ( a.sectionid IN (". $secid .") )" : '' )
                . ( $show_front == "0" ? "\n AND f.content_id IS NULL" : '' )
                . "\n ORDER BY a.created DESC LIMIT $count"
                ;
                $database->setQuery( $query );
                $rows = $database->loadObjectList();
                break;               
}

// needed to reduce queries used by getItemid for Content Items
//if ( ( $type == 1 ) || ( $type == 3 ) ) {
//        $bs         = $mainframe->getBlogSectionCount();
//        $bc         = $mainframe->getBlogCategoryCount();
//        $gbs         = $mainframe->getGlobalBlogSectionCount();
// }

// Output
?>

<?php
        $tabclass_arr=array("sectiontableentry2","sectiontableentry1");
        $tabcnt = 0;
?>

<table cellpadding="0" cellspacing="0" width="100%">
<?php
foreach ( $rows as $row ) {
        // get Itemid
        switch ( $type ) {
                case 2:
                        $query = "SELECT id"
                        . "\n FROM #__menu"
                        . "\n WHERE type = 'content_typed'"
                        . "\n AND componentid = $row->id"
                        ;
                        $database->setQuery( $query );       
//                        $Itemid = $database->loadResult();
                        $Itemid = $menu_itemid;
                        break;
                       
                case 3:
                        if ( $row->sectionid ) {
//                                $Itemid = $mainframe->getItemid( $row->id, 0, 0, $bs, $bc, $gbs );
                                $Itemid = $menu_itemid;
                        } else {
                                $query = "SELECT id"
                                . "\n FROM #__menu"
                                . "\n WHERE type = 'content_typed'"
                                . "\n AND componentid = $row->id"
                                ;
                                $database->setQuery( $query );       
//                                $Itemid = $database->loadResult();                               
                                $Itemid = $menu_itemid;
                        }
                        break;

                case 1:
                default:
//                        $Itemid = $mainframe->getItemid( $row->id, 0, 0, $bs, $bc, $gbs );
                        $Itemid = $menu_itemid;
                        break;
        }

        // Blank itemid checker for SEF
        if ($Itemid == NULL) {
                $Itemid = '';
        } else {
                $Itemid = '&Itemid='. $Itemid;
        }

        $link = sefRelToAbs( 'index.php?option=com_content&task=view&id='.$row->id.$Itemid );
?>

        <tr class="latestnews<?php echo $class_sfx; ?>">
                <td width="80%" class="<?php echo $tabclass_arr[$tabcnt]; ?>">
                &nbsp·&nbsp<a href="<?php echo $link; ?>" class="latestnews<?php echo $class_sfx; ?>">
                <? echo $row->title; ?>
                        </a>
                </td>
                <td width="20%" align="right" class="<?php echo $tabclass_arr[$tabcnt]; ?>"><div align="right">
                        <? if ( $show_time ==1 ) {
                                                        echo date('Y-m-d', strtotime($row->created));
                                                }
                        ?></div>
                </td>
        </tr>

        <?php
                if ($tabcnt == 1){
                        $tabcnt = 0;
                } else {
                        $tabcnt++;
                        }
}
?>
        <tr margin-top : 0 >
        <td colspan="2" align="center" ><div align="center">
                <?
                $more = sefRelToAbs( 'index.php?option=com_content&task=category&sectionid='.$row->sectionid.'&id='.$row->catid.$Itemid );
                ?>
                <a href=" <? echo $more; ?> " >
                更多</a> >>> </div></td>
        </tr>
</table>
为了使条目可以交替颜色显示,在模板的 CSS 文件中增加:
引用:
.sectiontableentry1 {
background-color : #254F25;
color:#FFFFFF;
}

.sectiontableentry2 {
background-color : #003300;
color:#FFFFFF;
font-size:10px;
}
如果要看一下效果,可以浏览:http://www.shannon-dd.com/index.php?option=com_content&task=section&id=4&Itemid=100

TOP

如果只想要个“更多”,应该只改哪儿就行?
mambo,想说爱你不容易

TOP

php文件中的最后几行:
引用:
       <tr margin-top : 0 >
        <td colspan="2" align="center" ><div align="center">
                <?
                $more = sefRelToAbs( 'index.php?option=com_content&task=category&sectionid='.$row->sectionid.'&id='.$row->catid.$Itemid );
                ?>
                <a href=" <? echo $more; ?> " >
                更多</a> >>> </div></td>
        </tr>

TOP

引用:
原帖由 shannon 于 2006-2-22 12:38 发表
php文件中的最后几行:

谢楼上的帅哥,您就是菩萨
mambo,想说爱你不容易

TOP

发新话题