Alternating rows background

Started by NoRad, August 28, 2004, 03:23:22 AM

Previous topic - Next topic

DAB Empire

How can the code below:

Quote from: [Unknown] on August 28, 2004, 06:37:20 AM
Sorry, I said Display, didn't I?  I meant MessageIndex.

Find:
foreach ($context['topics'] as $topic)
{
echo '
<tr>
<td class="windowbg2" valign="middle" align="center" width="5%">
<img src="', $settings['images_url'], '/topic/', $topic['class'], '.gif" alt="" />
</td>
<td class="windowbg2" valign="middle" align="center" width="4%">
<img src="', $settings['images_url'], '/post/', $topic['first_post']['icon'], '.gif" alt="" />
</td>
<td class="windowbg" valign="middle">
', $topic['first_post']['link'];

// Is this topic new? (assuming they are logged in!)
if ($topic['new'] && $context['user']['is_logged'])
echo '
<a href="', $scripturl, '?topic=', $topic['id'], '.from', $topic['newtime'], '#new"><img src="', $settings['images_url'], '/', $context['user']['language'], '/new.gif" alt="', $txt[302], '" border="0" /></a>';

echo '
<span class="smalltext">', $topic['pages'], '</span>
</td>
<td class="windowbg2" valign="middle" width="14%">
', $topic['first_post']['member']['link'], '
</td>
<td class="windowbg" valign="middle" width="4%" align="center">
', $topic['replies'], '
</td>
<td class="windowbg" valign="middle" width="4%" align="center">
', $topic['views'], '
</td>
<td class="windowbg2" valign="middle" width="22%"><span class="smalltext">
', $topic['last_post']['time'], '<br />
', $txt[525], ' ', $topic['last_post']['member']['link'], '
</span></td>';


Replace:
$alternate = true;
foreach ($context['topics'] as $topic)
{
echo '
<tr class="', $alternate ? 'windowbg' : 'windowbg2', '">
<td valign="middle" align="center" width="5%">
<img src="', $settings['images_url'], '/topic/', $topic['class'], '.gif" alt="" />
</td>
<td valign="middle" align="center" width="4%">
<img src="', $settings['images_url'], '/post/', $topic['first_post']['icon'], '.gif" alt="" />
</td>
<td valign="middle">
', $topic['first_post']['link'];

// Is this topic new? (assuming they are logged in!)
if ($topic['new'] && $context['user']['is_logged'])
echo '
<a href="', $scripturl, '?topic=', $topic['id'], '.from', $topic['newtime'], '#new"><img src="', $settings['images_url'], '/', $context['user']['language'], '/new.gif" alt="', $txt[302], '" border="0" /></a>';

echo '
<span class="smalltext">', $topic['pages'], '</span>
</td>
<td valign="middle" width="14%">
', $topic['first_post']['member']['link'], '
</td>
<td valign="middle" width="4%" align="center">
', $topic['replies'], '
</td>
<td valign="middle" width="4%" align="center">
', $topic['views'], '
</td>
<td valign="middle" width="22%"><span class="smalltext">
', $topic['last_post']['time'], '<br />
', $txt[525], ' ', $topic['last_post']['member']['link'], '
</span></td>';

$alternate = !$alternate;


-[Unknown]

Be used in 2.x?  It seems the lines of code are different.

Arantor

Considering that that code was posted 5 years ago, long before SMF 2 was considered, you can't. It's different code.

Please keep to the other thread in this board.
Holder of controversial views, all of which my own.


DAB Empire

The reason there's 2 threads, is because they're 2 pre-existing topics.  I am interested in the alternating row backgrounds in the message index (this thread) and additionally the board index (the other thread).

Arantor

Yes I know, but there is no need to keep posting in both, especially because this topic is completely irrelevant to your situation, because it deals specifically and singularly with 1.0/1.1, because it was started 5 years ago.
Holder of controversial views, all of which my own.


DAB Empire

Thought I'd figure it out on my own than.

MessageIndex.template.php find:

   foreach ($context['topics'] as $topic)
   {
      echo '
            <tr>
               <td class="windowbg2" valign="middle" align="center" width="5%">
                  <img src="', $settings['images_url'], '/topic/', $topic['class'], '.gif" alt="" />
               </td>
               <td class="windowbg2" valign="middle" align="center" width="4%">
                  <img src="', $settings['images_url'], '/post/', $topic['first_post']['icon'], '.gif" alt="" />
               </td>
               <td class="windowbg" valign="middle">
                  ', $topic['first_post']['link'];

      // Is this topic new? (assuming they are logged in!)
      if ($topic['new'] && $context['user']['is_logged'])
         echo '
                  <a href="', $scripturl, '?topic=', $topic['id'], '.from', $topic['newtime'], '#new"><img src="', $settings['images_url'], '/', $context['user']['language'], '/new.gif" alt="', $txt[302], '" border="0" /></a>';

      echo '
                  <span class="smalltext">', $topic['pages'], '</span>
               </td>
               <td class="windowbg2" valign="middle" width="14%">
                  ', $topic['first_post']['member']['link'], '
               </td>
               <td class="windowbg" valign="middle" width="4%" align="center">
                  ', $topic['replies'], '
               </td>
               <td class="windowbg" valign="middle" width="4%" align="center">
                  ', $topic['views'], '
               </td>
               <td class="windowbg2" valign="middle" width="22%"><span class="smalltext">
                  ', $topic['last_post']['time'], '<br />
                  ', $txt[525], ' ', $topic['last_post']['member']['link'], '
               </span></td>';


Replace with:

$alternate = true;
foreach ($context['topics'] as $topic)
{
// Do we want to seperate the sticky and lock status out?
if (!empty($settings['separate_sticky_lock']) && strpos($topic['class'], 'sticky') !== false)
$topic['class'] = substr($topic['class'], 0, strrpos($topic['class'], '_sticky'));
if (!empty($settings['separate_sticky_lock']) && strpos($topic['class'], 'locked') !== false)
$topic['class'] = substr($topic['class'], 0, strrpos($topic['class'], '_locked'));

// Calculate the colour class of the topic.
if ($context['can_approve_posts'] && $topic['unapproved_posts'])
$color_class = $topic['approved'] ? 'approvebg' : 'approvetbg';
else
$color_class = !empty($settings['separate_sticky_lock']) && $topic['is_sticky'] ? 'windowbg3' : 'windowbg';

echo '
<tr class="', $alternate ? 'windowbg' : 'windowbg2', '">
<td class="icon1">
<img src="', $settings['images_url'], '/topic/', $topic['class'], '.gif" alt="" />
</td>
<td class="icon2">
<img src="', $topic['first_post']['icon_url'], '" alt="" />
</td>
<td ', (!empty($topic['quick_mod']['modify']) ? 'id="topic_' . $topic['first_post']['id'] . '" onmouseout="mouse_on_div = 0;" onmouseover="mouse_on_div = 1;" ondblclick="modify_topic(\'' . $topic['id'] . '\', \'' . $topic['first_post']['id'] . '\', \'' . $context['session_id'] . '\');"' : ''), '>';

if (!empty($settings['separate_sticky_lock']))
echo '
' , $topic['is_locked'] ? '<img src="' . $settings['images_url'] . '/icons/quick_lock.gif" align="right" alt="" id="lockicon' . $topic['first_post']['id'] . '" style="margin: 0;" />' : '' , '
' , $topic['is_sticky'] ? '<img src="' . $settings['images_url'] . '/icons/show_sticky.gif" align="right" alt="" id="stickyicon' . $topic['first_post']['id'] . '" style="margin: 0;" />' : '';

echo '
', $topic['is_sticky'] ? '<b>' : '' , '<span id="msg_' . $topic['first_post']['id'] . '">', $topic['first_post']['link'], (!$context['can_approve_posts'] && !$topic['approved'] ? '&nbsp;<em>(' . $txt['awaiting_approval'] . ')</em>' : ''), '</span>', $topic['is_sticky'] ? '</b>' : '';

// Is this topic new? (assuming they are logged in!)
if ($topic['new'] && $context['user']['is_logged'])
echo '
<a href="', $topic['new_href'], '" id="newicon' . $topic['first_post']['id'] . '"><img src="', $settings['lang_images_url'], '/new.gif" alt="', $txt['new'], '" /></a>';

echo '
<small id="pages' . $topic['first_post']['id'] . '">', $topic['pages'], '</small>
</td>
<td class="starter">
', $topic['first_post']['member']['link'], '
</td>
<td class="' , $topic['is_sticky'] ? '3' : '' , ' replies">
', $topic['replies'], '
</td>
<td class="' , $topic['is_sticky'] ? '3' : '' , ' views">
', $topic['views'], '
</td>
<td class="lastpost">
<a href="', $topic['last_post']['href'], '"><img src="', $settings['images_url'], '/icons/last_post.gif" alt="', $txt['last_post'], '" title="', $txt['last_post'], '" style="float: right;" /></a>
<span class="smalltext">
', $topic['last_post']['time'], '<br />
', $txt['by'], ' ', $topic['last_post']['member']['link'], '
</span>
</td>';
$alternate = !$alternate;


Make a backup in case it doesn't work for you.  Worked fine for me by comparing the original mod to the new lines of code.

Advertisement: