Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: Col on December 11, 2007, 04:33:06 PM

Title: Help with small piece of code on BoardIndex.template.php
Post by: Col on December 11, 2007, 04:33:06 PM
Hi,

I'm trying to modify a theme that uses a background image on the board index to indicate new posts to the board. The image is floated to the far right from the board title, which I find unsatisfactory. Obviously, I cannot float it to the left as it will end up behind the board title. I can remove the code that displays the image easily enough, but am having trouble reintegrating the code to display the image as an image, not a background image.

I'm attempting to use img src tags instead, but I'm making errors with the php code.

Original code:

echo '
<dt', $board['new'] ? ' class="new"' : '', '', $board['children_new'] ? ' class="new"' : '', '><a href="', $board['href'], '" name="b', $board['id'], '">', $board['name'], '</a>';


Edited code that works, but no image displayed:

echo '
<dt><a href="', $board['href'], '" name="b', $board['id'], '">', $board['name'], '</a>';


Attempted insertion of code to display image next to the board title:

<dt><a href="', $board['href'], '" name="b', $board['id'], '">', $board['name'], '</a>', $board['new'] ? ' <img src="', $settings['images_url'], '/newposts.gif" alt="', $txt[333], '" />' : '', '', $board['children_new'] ? ' <img src="', $settings['images_url'], '/newposts.gif" alt="', $txt[333], '" />' : '', ';

I cannot code at all, so I'm just trying to copy the syntax, but failing, possibly miserably. Help would be greatly appreciated.

Thanks.
Title: Re: Help with small piece of code on BoardIndex.template.php
Post by: Alpha_Vector on December 11, 2007, 06:24:51 PM
You could start by changing "dt" with "td". ;)
Title: Re: Help with small piece of code on BoardIndex.template.php
Post by: Col on December 11, 2007, 06:33:22 PM
No, 'dt' is correct. It is not table based. I would use 'li', but I'm not recoding the whole theme.
Title: Re: Help with small piece of code on BoardIndex.template.php
Post by: Rumbaar on December 12, 2007, 03:14:48 AM
Can you post more the surrounding code, so can better help coding it.

You'll need to put in if statements for each possibilities, $board['new'], $board['children_new'] & none.  Take a look now the on, on2 and off images are inserted into the cells in the default BoardIndex.template.php file.
Title: Re: Help with small piece of code on BoardIndex.template.php
Post by: Col on December 12, 2007, 08:23:53 AM
Hi,

I thought there was enough there - no? I included the whole of the original section in the first code box (please note, if you are using IE, the code is truncated because of a bug in the template here (or within IE, depending upon your point of view)).

I'll try posting the original code in a quote box with smilies off, and see if it posts better. I've added some surrounding code too, just in case.

Thanks for the offer help.

Quote/* Each board in each category's boards has:
         new (is it new?), id, name, description, moderators (see below), link_moderators (just a list.),
         children (see below.), link_children (easier to use.), children_new (are they new?),
         topics (# of), posts (# of), link, href, and last_post. (see below.) */
         foreach ($category['boards'] as $board)
         {
            echo '
            <dt', $board['new'] ? ' class="new"' : '', '', $board['children_new'] ? ' class="new"' : '', '><a href="', $board['href'], '" name="b', $board['id'], '">', $board['name'], '</a>';
            
            // Show the "Child Boards: ". (there's a link_children but we're going to bold the new ones...)
            if (!empty($board['children']))
            {
               // Sort the links into an array with new boards bold so it can be imploded.
               $children = array();
               /* Each child in each board's children has:
                     id, name, description, new (is it new?), topics (#), posts (#), href, link, and last_post. */
               foreach ($board['children'] as $child)
               {
                     $child['link'] = '<a href="' . $child['href'] . '" title="' . ($child['new'] ? $txt[333] : $txt[334]) . ' (' . $txt[330] . ': ' . $child['topics'] . ', ' . $txt[21] . ': ' . $child['posts'] . ')">' . $child['name'] . '</a>';
                     $children[] = $child['new'] ? '' . $child['link'] . '' : $child['link'];
               }

               echo '<br /><span class="chboards">[<strong>', $txt['parent_boards'], '</strong>: ', implode(' | ', $children), ']</span>';
            }
                               
                                echo '</dt>
                                <dd class="msgicon"><a href="', $scripturl, '?action=unread;board=', $board['id'], '.0">';
                               
                                // If the board is new, show a strong indicator.
            if ($board['new'])
               echo '<img src="', $settings['images_url'], '/on.gif" alt="', $txt[333], '" title="', $txt[333], '" />';
            // This board doesn't have new posts, but its children do.
            elseif ($board['children_new'])
               echo '<img src="', $settings['images_url'], '/on.gif" alt="', $txt[333], '" title="', $txt[333], '" />';
            // No new posts at all! The agony!!
            else
               echo '<img src="', $settings['images_url'], '/off.gif" alt="', $txt[334], '" title="', $txt[334], '" />';

                                echo '</a></dd>
            <dd class="msgbody">', $board['description'];

Edit: code tags are are truncating the code in IE, so I'm using quote tags instead, with smilies disabled.

Thanks.
Title: Re: Help with small piece of code on BoardIndex.template.php
Post by: Rumbaar on December 12, 2007, 04:22:11 PM
Ok just call the check on the outside of the "<dt>"

<dt><a href="', $board['href'], '" name="b', $board['id'], '">', $board['name'], '</a>', $board['new'] ? '<img src="', $settings['images_url'], '/newposts.gif" alt="', $txt[333], '" />' : '', '', $board['children_new'] ? '<img src="', $settings['images_url'], '/newposts.gif" alt="', $txt[333], '" />' : '', '';

As long as the paths are correct and the image is actually there, it should work.  Though it you're going to trigger for child I'd make a different looking image.
Title: Re: Help with small piece of code on BoardIndex.template.php
Post by: Col on December 17, 2007, 09:14:51 AM
Thanks Rumbaar,

I'll try that out later today or tommorw. :)
Title: Re: Help with small piece of code on BoardIndex.template.php
Post by: Rumbaar on December 17, 2007, 04:08:14 PM
Best of luck.  Let us know how it went for you.