发新话题
打印

[求助] 如何将mod_latestnews最新文章的"更多..."右对齐

如何将mod_latestnews最新文章的"更多..."右对齐

我将<td align="left" valign="top">
    <a href="<?php echo $link_on;?>" <?php echo $target;?> class="readon<?php echo $class_sfx; ?>">
    <?php echo _READ_MORE;?>    </a>    </td>
字段代码改为右对齐还是不行,大家帮帮忙,我用的是5.2.0中的mod_latestnews
复制内容到剪贴板
代码:
<?php
/**
* @version $Id: mod_latestnews.php,v 1.1 2005/07/22 01:58:29 eddieajau 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 ) );
$target  = intval( $params->get( 'target', 0 ) );
$catid   = trim( $params->get( 'catid' ) );
$secid   = trim( $params->get( 'secid' ) );
$show_front = $params->get( 'show_front', 1 );
$class_sfx = $params->get( 'moduleclass_sfx' );
$show_headline = intval( $params->get( 'show_headline', 0 ) );
$moduletitle = $params->get( 'moduletitle' );
$seccat_style = intval( $params->get( 'seccat_style', 0 ) ); // style of section/category, 0 -- list, 1 -- blog
$count = $show_headline ? $count + 1 : $count;
// Title Length
$titlelength = intval( $params->get( 'titlelength', 40 ) );
$now   = date( 'Y-m-d H:i:s', time() + $mosConfig_offset * 60 * 60 );
$more = _MORE . ( $show_headline ? $moduletitle : '' );
$linkmore = '';
if (!empty($catid)) {
$pieces = explode(",", $catid);
$catid = $pieces[0];
if ($seccat_style) {
  $linkmore = 'index.php?option=com_content&task=blogcategory&id='.$catid;
}
else {
  $linkmore = 'index.php?option=com_content&task=category&id='.$catid;
}
}
else {
if (!empty($secid)) {
  $pieces = explode(",", $secid);
  $secid = $pieces[0];
  if ($seccat_style) {
   $linkmore = 'index.php?option=com_content&task=blogsection&id='.$secid;
  }
  else {
   $linkmore = 'index.php?option=com_content&task=section&id='.$secid;
  }
}
}

switch ($target) {
// cases are slightly different
case 1:
// open in a new window
$target = ' target="_blank" ';
break;
default:
// open in parent window
$target = '';
break;
}
$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.introtext, a.created_by_alias, a.created, a.urls, 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();
}

if (!is_null($rows)) {
// Output begin
?>
<table border=0 cellpadding=0 cellspacing=0>
<tr>
<?php if ( ( $type == 1 ) && $show_headline ) {
  $row = array_shift($rows);
  // get Itemid
  $_Itemid = $mainframe->getItemid( $row->id, 0, 0, $bs, $bc, $gbs );
  // Blank itemid checker for SEF
  if ($_Itemid == NULL) {
   $_Itemid = '';
  } else {
   $_Itemid = '&Itemid='. $_Itemid;
  }
  if ( $row->urls ) {
   $link_on = 'index.php?option=com_content&task=wrapper&id='. $row->id . $_Itemid;
  }
  else {
   $link_on = 'index.php?option=com_content&task=view&id='. $row->id . $_Itemid;
  }
  $link_on = sefRelToAbs($link_on);
  $Author = '  ' . $row->created_by_alias ? $row->created_by_alias : $row->author;
  $create_date = '  ' . mosFormatDate( $row->created );
?>
  <td width="50%" align="left" valign="top">
   <table border="0" cellpadding="0" cellspacing="0">
   <tr>
    <th align="left" valign="top">
    <?php
    if (!empty($linkmore)) {
    ?>
    <a href="<?php echo sefRelToAbs( $linkmore . $_Itemid ); ?>" >
    <?php echo $moduletitle; ?>    </a>
    <?php
    }
    else {
     echo $moduletitle;
    }
    ?>   </th>
   </tr>
   <tr>
    <td class="contentheading<?php echo $class_sfx; ?>" align="left" valign="top" width="100%">
    <a href="<?php echo $link_on;?>" <?php echo $target;?> class="contentpagetitle<?php echo $class_sfx; ?>">
    <?php echo $row->title;?>    </a>    </td>
   </tr>
   <tr>
    <td align="left" valign="top">
    <span class="small">
    <?php echo $Author; ?>    </span>
    <span class="createdate">
    <?php echo $create_date; ?>    </span>    </td>
   </tr>
  
   <tr>
    <td align="left" valign="top">
    <?php
    // displays Item introtext
    echo $row->introtext;
    ?>    </td>
   </tr>
   <tr>
    <td align="left" valign="top">
    <a href="<?php echo $link_on;?>" <?php echo $target;?> class="readon<?php echo $class_sfx; ?>">
    <?php echo _READ_MORE;?>    </a>    </td>
   </tr>
   </table>  </td>
<?php }
?>
  <td align="left" valign="top">
   <ul class="latestnews<?php echo $class_sfx; ?>">
   <?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();
      break;
      
     case 3:
      if ( $row->sectionid ) {
       $_Itemid = $mainframe->getItemid( $row->id, 0, 0, $bs, $bc, $gbs );
      } else {
       $query = "SELECT id"
       . "\n FROM #__menu"
       . "\n WHERE type = 'content_typed'"
       . "\n AND componentid = $id";
       $database->setQuery( $query );
       $_Itemid = $database->loadResult();   
      }
      break;
   
     case 1:
     default:
      $_Itemid = $mainframe->getItemid( $row->id, 0, 0, $bs, $bc, $gbs );
      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 );
    ?>
    <li class="latestnews<?php echo $class_sfx; ?>">
    <a href="<?php echo $link; ?>"<?php echo $target; ?>class="latestnews<?php echo $class_sfx; ?>">
    <?php
     $title =  $row->title;
     if (strlen($title) > $titlelength) {
      $title =  substr( $title, 0, $titlelength ) . "...";
     }
     echo $title . ' (' . date('m-d', strtotime( $row->created ) ) . ')';
    ?>
    </a>    </li>
    <?php
   }
   // Show More
   if (!empty($linkmore)) {
    ?>
    <div id="readmore"><a href="<?php echo sefRelToAbs( $linkmore . $_Itemid ); ?>" >
    <?php echo $more; ?>
    </a>    </div>
    <?php
   }
   ?>
   </ul>   </td>
</tr>
</table>
<?php
// end of output
}
?>
[ 本帖最后由 替补队员 于 2007-8-14 12:00 编辑 ]

TOP

说实话!我没看到更多在哪里!或者和更多同样意义的文字在哪里!more都是程序代码!没有显示出来的文字呀
我开源,我开心 -- Mambo中国
More Simple, More Powerful
愈简,愈强 -- Mambo中国整站系统

TOP

复制内容到剪贴板
代码:
<div id="readmore"><a href="<?php echo sefRelToAbs( $linkmore . $_Itemid ); ?>" >
    <?php echo $more; ?>
    </a>    </div>
在模版的 css 文件中,加 readmore class,嘻嘻,找到一个小bug, readmore 应该是 class 而不是 id
剑虽残,尚可刺bug -- Mambo中国挑bug组
我开源,我开心,分享建站乐趣 -- Mambo中国

TOP

谢谢两位前辈的关怀,按照残前辈的提示,问题已经搞定

不过用class和id都能解决问题,不知道有何区别影响

为了其他和我一样的入门菜鸟能看懂,具体解决办法:

方法一,在模板CSS文件中添加如下代码
复制内容到剪贴板
代码:
#readmore {
text-align: right;
}
方法二,在模板CSS文件中添加如下代码
复制内容到剪贴板
代码:
.readmore{
text-align: right;
}
并将“最新文章”模块mod_latestnews.php文件中的
复制内容到剪贴板
代码:
<div id="readmore"><a href="<?php echo sefRelToAbs( $linkmore . $_Itemid ); ?>" >
    <?php echo $more; ?>
    </a>    </div>
改为
复制内容到剪贴板
代码:
<div class="readmore"><a href="<?php echo sefRelToAbs( $linkmore . $_Itemid ); ?>" >
    <?php echo $more; ?>
    </a>    </div>
(就是将id改为class)

===============================================

看来这个问题是模板css未定义readmore样式引起的,可能换个模板也许就正常了^_^
不知道总结得对不对,希望前辈们再补充一下

[ 本帖最后由 替补队员 于 2007-8-15 01:43 编辑 ]

TOP

赞!
css 的 id 是只能出现一次, class 可以重复使用

这里用 id 是不对的,因为一个网页中可以有很多个地方用到 readmore

我也得修改 mod_latestnews.php

模版css的修改,只需用方法二

TOP

建议用第二个方法改掉!为了可以重复使用
我开源,我开心 -- Mambo中国
More Simple, More Powerful
愈简,愈强 -- Mambo中国整站系统

TOP

发新话题