News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Changing windowbg depending on category

Started by HunterP, March 21, 2011, 02:08:56 PM

Previous topic - Next topic

HunterP


Hi there,

I wanted to do this for a long time, but wanted to wait until I upgraded to RC5, so here comes my question :)

In the recent messages I want to make the "team" category better visible to change the background color. In Recent.template.php I see this line which I want to modify :

               </td><td class="windowbg', $topic['is_sticky'] && !empty($settings['separate_sticky_lock']) ? '3' : '', '" width="48%" valign="middle">', $topic['is_locked'] && !empty($settings['separate_sticky_lock']) ? '

I've tried to add $context['post']['board']['id'] and the same for the category, but I must be doing something wrong. Unfortunately I've already deleted my code.

Lets say that I want to add 'windowbg4' when the topic is in category 25.

How do I do this? :)

Arantor

And what if the topic is sticky or locked?

HunterP

Quote from: Arantor on March 21, 2011, 02:12:46 PM
And what if the topic is sticky or locked?

I already ran into that question myself :) Actually, I don't really care for this specific category as it is only visible for me and my moderator team. There are not much sticky/locked topics.

HunterP


In Recent.php, UnreadTopics() I want to make the category available in the $topics array :

      // And build the array.
      $context['topics'][$row['id_topic']] = array(

I've added

         'category' => array(
            'id' => $row['id_cat'],
            'name' => $row['cname'],
            'href' => $scripturl . '#c' . $row['id_cat'],
            'link' => '<a href="' . $scripturl . '#c' . $row['id_cat'] . '">' . $row['cname'] . '</a>'
         ),

before

         'board' => array(
            'id' => $row['id_board'],
            'name' => $row['bname'],
            'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
            'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['bname'] . '</a>'
         )

But no succes :(

HunterP

#4

Fixed it myself, added in Recent.php :

   // This part is the same for each query.
   $select_clause = '
            ms.subject AS first_subject, ms.poster_time AS first_poster_time, ms.id_topic, t.id_board, b.id_cat, b.name AS bname,
            t.num_replies, t.num_views, ms.id_member AS id_first_member, ml.id_member AS id_last_member,
            ml.poster_time AS last_poster_time, IFNULL(mems.real_name, ms.poster_name) AS first_poster_name,
            IFNULL(meml.real_name, ml.poster_name) AS last_poster_name, ml.subject AS last_subject,
            ml.icon AS last_icon, ms.icon AS first_icon, t.id_poll, t.is_sticky, t.locked, ml.modified_time AS last_modified_time,
            IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1 AS new_from, SUBSTRING(ml.body, 1, 385) AS last_body,
            SUBSTRING(ms.body, 1, 385) AS first_body, ml.smileys_enabled AS last_smileys, ms.smileys_enabled AS first_smileys, t.id_first_msg, t.id_last_msg';

and

      $request = $smcFunc['db_query']('substring', '
         SELECT ' . $select_clause . '
         FROM {db_prefix}topics AS t
            INNER JOIN {db_prefix}messages AS ms ON (ms.id_topic = t.id_topic AND ms.id_msg = t.id_first_msg)
            INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg)
            INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
            INNER JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
            LEFT JOIN {db_prefix}members AS mems ON (mems.id_member = ms.id_member)
            LEFT JOIN {db_prefix}members AS meml ON (meml.id_member = ml.id_member)
            LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member})
            LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = t.id_board AND lmr.id_member = {int:current_member})

and

         'views' => comma_format($row['num_views']),
         'category' => array(
            'id' => $row['id_cat']
         ),

         'board' => array(
            'id' => $row['id_board'],
            'name' => $row['bname'],
            'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
            'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['bname'] . '</a>'
         )

In Recent.template.php :

               <td class="windowbg2" valign="middle" align="center" width="4%">
                  <img src="' . $settings['images_url'] . '/topic/' . $topic['class'] . '.gif" alt="" />
               </td><td class="windowbg2" valign="middle" align="center" width="4%">
                  <img src="' . $topic['first_post']['icon_url'] . '" alt="" align="middle" />
               </td><td class="windowbg', $topic['is_sticky'] && !empty($settings['separate_sticky_lock']) ? '3' : '' , '"' , $topic['category']['id'] == 29 ? ' id="modforum"' : '' , 'width="48%" valign="middle">', $topic['is_locked'] && !empty($settings['separate_sticky_lock']) ? '

Topics from the category "Moderator Forum" (id==29) will be parsed as :

<td width="48%" valign="middle" id="modforum" class="windowbg">

CSS :

#modforum
{
   border: 2px solid #ff0000;
}

Results in (see attachment)

HunterP


Does anyone like this? I'm thinking about making this a MOD.

HunterP

Quote from: HunterP on April 01, 2011, 08:09:56 PM
Does anyone like this? I'm thinking about making this a MOD.

Think it's ready, anyone willing to test it? :)

Advertisement: