0

我正在为我的网站使用 Joomla 1.5,并希望使 RSS 提要模块 (mod_feed) 以不同的颜色显示交替的行,希望这里有人能提供帮助!这是模块布局的主要代码(我删除了顶部

<div style="direction: <?php echo $rssrtl ? 'rtl' :'ltr'; ?>; text-align: <?php echo $rssrtl ? 'right' :'left'; ?> ! important">
<?php
if( $feed != false )
{
 //image handling
 $iUrl  = isset($feed->image->url)   ? $feed->image->url   : null;
 $iTitle = isset($feed->image->title) ? $feed->image->title : null;
 ?>
 <table cellpadding="0" cellspacing="0" class="moduletable<?php echo $params->get('moduleclass_sfx'); ?>">
 <?php
 // feed description
 if (!is_null( $feed->title ) && $params->get('rsstitle', 1)) {
  ?>
  <tr>
   <td>
    <strong>
     <a href="<?php echo str_replace( '&', '&amp', $feed->link ); ?>" target="_blank">
      <?php echo $feed->title; ?></a>
    </strong>
   </td>
  </tr>
  <?php
 }

 // feed description
 if ($params->get('rssdesc', 1)) {
 ?>
  <tr>
   <td><?php echo $feed->description; ?></td>
  </tr>
  <?php
 }

 // feed image
 if ($params->get('rssimage', 1) && $iUrl) {
 ?>
  <tr>
   <td><img src="<?php echo $iUrl; ?>" alt="<?php echo @$iTitle; ?>"/></td>
  </tr>
 <?php
 }

 $actualItems = count( $feed->items );
 $setItems    = $params->get('rssitems', 5);

 if ($setItems > $actualItems) {
  $totalItems = $actualItems;
 } else {
  $totalItems = $setItems;
 }
 ?>
 <tr>
  <td>
   <ul class="newsfeed <?php echo $params->get( 'moduleclass_sfx'); ?>"  >
   <?php
   $words = $params->def('word_count', 0);
   for ($j = 0; $j < $totalItems; $j ++)
   {
    $currItem = & $feed->items[$j];
    // item title
    ?>
    <li>
    <?php
    if ( !is_null( $currItem->get_link() ) ) {
    ?>
     <a href="<?php echo $currItem->get_link(); ?>" target="_blank">
     <?php echo $currItem->get_title(); ?></a>
    <?php
    }

    // item description
    if ($params->get('rssitemdesc', 1))
    {
     // item description
     $text = $currItem->get_description();
     $text = str_replace('&apos;', "'", $text);

     // word limit check
     if ($words)
     {
      $texts = explode(' ', $text);
      $count = count($texts);
      if ($count > $words)
      {
       $text = '';
       for ($i = 0; $i < $words; $i ++) {
        $text .= ' '.$texts[$i];
       }
       $text .= '...';
      }
     }
     ?>
     <div style="text-align: <?php echo $params->get('rssrtl', 0) ? 'right': 'left'; ?> ! important" class="newsfeed_item<?php echo $params->get( 'moduleclass_sfx'); ?>"  >
      <?php echo $text; ?>
     </div>
     <?php
    }
    ?>
    </li>
    <?php
   }
   ?>
   </ul>
  </td>
  </tr>
 </table>
<?php } ?>
</div>
4

1 回答 1

2

您可以使用模运算符来确定您的循环变量 ($j) 当前是奇数还是偶数,然后根据需要应用 CSS 类。在一行中,您可以将开始 li 标记更改为如下内容:

<li class="<? ($j % 2) ? echo "even" : echo "odd"; ?>">

CSS可以这样应用:

.newsfeed li.even{ background: #fff; }
.newsfeed li.odd{ background: #efefef; }

交替行的模运算符 - Snook.ca

于 2009-11-08T20:34:40.963 回答