SSI Recent Topic Line BG Highlight

Started by codnerd, November 29, 2012, 12:14:13 AM

Previous topic - Next topic

codnerd

I am wondering if I could add alternating highlight bg's behind the text, and still have it transparent.

How it is now, stock:


Example picture: (photoshopped, not perfect)



Code that I think needs to be edited:
echo '
<table border="0" class="ssi_table">';
foreach ($posts as $post)
echo '
<tr>
             
<td valign="top">
<a href="', $post['href'], '">', $post['subject'], '</a>
', $txt['by'], ' ', $post['poster']['link'], '
', !$post['is_new'] ? '' : '<a href="' . $scripturl . '?topic=' . $post['topic'] . '.msg' . $post['new_from'] . ';topicseen#new" rel="nofollow"><img src="' . $settings['lang_images_url'] . '/new.gif" alt="' . $txt['new'] . '" /></a>', '
</td>

</tr>';
echo '
</table>';


*Also, if you have any cool ideas to make it look better/stand out more, tell please.

MrPhil

1. Look at one of the SMF routines for listing posts. You can either keep count of the number of rows, and use modulo 2 arithmetic to select the class (probably for a full-width <div>) for odd and even rows, or just set a flag that you're on an even or odd row (initial odd, flip at the end of each row's output).

2. Normally this would be done with two classes with two different background colors, but if you want some transparency you'd have to set a background image with some translucency (.png would be best), for the two different classes for odd and even rows. The image can be as little as 1x1 px, so long as it's tiled (repeated in both x and y).

IchBin™

Another option is to add some javascript to do this type of thing too. Jquery has this stuff built in if you'd like to look at it.

http://api.jquery.com/odd-selector/
IchBin™        TinyPortal

codnerd

Would you be able to show me in code?
If not, it is ok.

Colin

JQuery is probably the easiest way to do it.

The link Ichbin sent you has a simple example.


<!DOCTYPE html>
<html>
<head>
  <style>

  table {
    background:#f3f7f5;
  }
  </style>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
  <table border="1">
    <tr><td>Row with Index #0</td></tr>
    <tr><td>Row with Index #1</td></tr>

    <tr><td>Row with Index #2</td></tr>
    <tr><td>Row with Index #3</td></tr>
  </table>
<script>$("tr:odd").css("background-color", "#bbbbff");</script>

</body>
</html>
"If everybody is thinking alike, then somebody is not thinking." - Gen. George S. Patton Jr.

Colin

codnerd

How would I put/integrate that with the SSI?

IchBin™

Right where the code echo's out the table in SSI.php you just add the code you need to add the javascript.
IchBin™        TinyPortal

codnerd

Tried, but it did not integrate even close to right.

Normal Code:

echo '
<table border="0" class="ssi_table">
    ';
foreach ($posts as $post)
echo '
<tr>
             
<td valign="top">
<a href="', $post['href'], '">', $post['subject'], '</a>
', $txt['by'], ' ', $post['poster']['link'], '
', !$post['is_new'] ? '' : '<a href="' . $scripturl . '?topic=' . $post['topic'] . '.msg' . $post['new_from'] . ';topicseen#new" rel="nofollow"><img src="' . $settings['lang_images_url'] . '/new.gif" alt="' . $txt['new'] . '" /></a>', '
</td>

</tr>';
echo '
</table>';


Failed integrated code:

echo '
<table border="0" class="ssi_table">
     <style>

  table {
    background:#f3f7f5;
  }
  </style>
  <script src="http://code.jquery.com/jquery-latest.js"></script>

  <table border="1">
    <tr><td>Row with Index #0</td></tr>
    <tr><td>Row with Index #1</td></tr>

    <tr><td>Row with Index #2</td></tr>
    <tr><td>Row with Index #3</td></tr>
  </table>
<script>$("tr:odd").css("background-color", "#bbbbff");</script>';
foreach ($posts as $post)
echo '
<tr>
             
<td valign="top">
<a href="', $post['href'], '">', $post['subject'], '</a>
', $txt['by'], ' ', $post['poster']['link'], '
', !$post['is_new'] ? '' : '<a href="' . $scripturl . '?topic=' . $post['topic'] . '.msg' . $post['new_from'] . ';topicseen#new" rel="nofollow"><img src="' . $settings['lang_images_url'] . '/new.gif" alt="' . $txt['new'] . '" /></a>', '
</td>

</tr>';

Joker™

SSI.php (Make backup of file before editing)

Code (Find:) Select
echo '
<table border="0" class="ssi_table">';
foreach ($posts as $post)
echo '
<tr>
<td align="right" valign="top" nowrap="nowrap">
[', $post['board']['link'], ']
</td>
<td valign="top">
<a href="', $post['href'], '">', $post['subject'], '</a>
', $txt['by'], ' ', $post['poster']['link'], '
', !$post['is_new'] ? '' : '<a href="' . $scripturl . '?topic=' . $post['topic'] . '.msg' . $post['new_from'] . ';topicseen#new" rel="nofollow"><img src="' . $settings['lang_images_url'] . '/new.gif" alt="' . $txt['new'] . '" /></a>', '
</td>
<td align="right" nowrap="nowrap">
', $post['time'], '
</td>
</tr>';
echo '
</table>';


Code (add after:) Select
    echo '<script>$("table.ssi_table tr:odd").css("background-color", "#bbbbff");</script>';


Moreover have you included jQuery? As you required to load it to make usage of its functions.

If you haven't loaded jQuery then you can load it in index.template.php of the theme you are using

Code (Find:) Select
// Here comes the JavaScript bits!

Code (Add before) Select
echo '<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
if (typeof jQuery == \'undefined\') {
document.write("<script type=\"text/javascript\" src=\"', $settings['default_theme_url'], '/scripts/jquery-1.8.3.min.js\"><\/script>");
}';


- Download the jquery file form here
- Place it in themes/default/scripts
Github Profile
Android apps
Medium

How to enable Post Moderation

"For the wise man looks into space and he knows there is no limited dimensions." - Laozi

All support seeking PM's get microwaved

codnerd

Added it all in exactly as you showed, and hoped it would work.
Did not make a difference, and was not able to see a difference in the page source.

I don't think the line "<script>$("table.ssi_table tr:odd").css("background-color..." was called in the previous code so it did not take effect.
Please help.

Joker™

Can you guide us with a link where recent posts from SSI.php has been shown.
Github Profile
Android apps
Medium

How to enable Post Moderation

"For the wise man looks into space and he knows there is no limited dimensions." - Laozi

All support seeking PM's get microwaved


Joker™

It seems jQuery hasn't been loaded on the pages where you are trying to use it.

P.S - If you can, place your links in this topic as it might get you more help.
Github Profile
Android apps
Medium

How to enable Post Moderation

"For the wise man looks into space and he knows there is no limited dimensions." - Laozi

All support seeking PM's get microwaved

codnerd

It is still not working, but I now understand the code you had me put in to get it to work.
Any idea why the jquery is not being called?

Code added in SSI.php under recentTopics SSI:
echo '
<table border="0" class="ssi_table">';
foreach ($posts as $post)
echo '
<tr>
             
<td valign="top">
<a href="', $post['href'], '">', $post['subject'], '</a>
', $txt['by'], ' ', $post['poster']['link'], '
', !$post['is_new'] ? '' : '<a href="' . $scripturl . '?topic=' . $post['topic'] . '.msg' . $post['new_from'] . ';topicseen#new" rel="nofollow"><img src="' . $settings['lang_images_url'] . '/new.gif" alt="' . $txt['new'] . '" /></a>', '
</td>

</tr>';
echo '
</table>';
   
      echo '<script>$("table.ssi_table tr:odd").css("background-color", "#ffffff");</script>';
}


Code added in index.template.php in my custom theme:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
if (typeof jQuery == \'undefined\') {
document.write("<script type=\"text/javascript\" src=\"', $settings['default_theme_url'], 'scripts/jquery-1.8.3.min.js\"><\/script>

codnerd

Also, just to test I tried adding the following code in the w3 editor and it did not work.

<!DOCTYPE html>
<html>
<body>

<table border="0" class="ssi_table">
<tr>
    <td>
        test
    </td>
</tr>
<tr>
    <td>
        test
    </td>
</tr>
<tr>
    <td>
        test
    </td>
</tr>
</table>

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
if (typeof jQuery == \'undefined\') {
document.write("<script type=\"text/javascript\" src=\"', $settings['default_theme_url'], 'scripts/jquery-1.8.3.min.js\"><\/script>
<script>$("table.ssi_table tr:odd").css("background-color", "#000000");</script>

</body>
</html>

Joker™

<!DOCTYPE html>
<html>
<body>

<table border="0" class="ssi_table">
<tr>
    <td>
        test
    </td>
</tr>
<tr>
    <td>
        test
    </td>
</tr>
<tr>
    <td>
        test
    </td>
</tr>
</table>

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
if (typeof jQuery == 'undefined') {
document.write('<script type=\"text/javascript\" src=\"', $settings['default_theme_url'], 'scripts/jquery-1.8.3.min.js\"><\/script>')
        }
    </script>
<script>$("table.ssi_table tr:odd").css("background-color", "#000000");</script>

</body>
</html>


Place this code in an html file and upload the file somewhere (test or live site), and see how this works.
Github Profile
Android apps
Medium

How to enable Post Moderation

"For the wise man looks into space and he knows there is no limited dimensions." - Laozi

All support seeking PM's get microwaved

codnerd

Thanks, worked great. Had this displayed on my portal, but was putting the java code in my SMF install.
Marking solved.

Advertisement: