News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Theme adjustment - Unread Posts list categories

Started by NoRad, August 31, 2004, 08:33:31 PM

Previous topic - Next topic

NoRad

When clicking on unread posts they appear to be ordered by most recent? My users are used to a different format and I'm wondering how I can implement this into a theme (if that's the way to do it). I would like to have it so that the most recent posts are grouped in categories and sorted the same way with a little divider header that tells the category.

For example... If you have 3 new posts on the SMF site they would group like this:


General Discussion and Feedback
-----------------------------------------------------------
Introduction to Simple Machines  New  « 1 2 3  All »

Administration and Functionality
------------------------------------------------------------
Cannot stay logged in - cookies (local mode?)  « 1 2  All »
Strange problem, Theme Problem?  New

[Unknown]

This can be done, but it's not exactly simple.

It would involve taking the topics and resorting them by board, and then displaying the boards dynamically... how comfortable are you with PHP so far?

-[Unknown]

NoRad

I've gotten the basics down, but I'm not quite there with the php + mysql, although I'm sure the mySQL can't be too different than what I used to do with ASP + msSQL? A week ago I picked up the PHP + mySQL BIBLE and I'm about 8 chapters into it at the moment. Good book.

[Unknown]

Actually, this wouldn't involve anything in the matter of MySQL - just PHP in the template.

-[Unknown]

NoRad

Well, point me in the right direction and I'll have a go at it I suppose. I read on the FAQ that I need to work with these files:

# Recent - recent posts, unread topics, and unread replies.
   Sub templates: main, unread, replies


Is that correct? I think those are all in 1 file as sub templates? What's the one file?

[Unknown]

The one file is Themes/yourtheme/Recent.template.php.  The sub template you want is unread.

In there, you'll see:

foreach ($context['topics'] as $topic)
{
echo '
...
</tr>';
}


Basically, you want to replace this with:

$boards = array();
foreach ($context['topics'] as $topic)
$boards[$topic['board']['id']] = $topic['board'];

foreach ($boards as $board)
{
echo '
<tr class="catbg">
<td colspan="7">', $board['link'], '</td>
</tr>';

foreach ($context['topics'] as $topic)
{
if ($topic['board']['id'] != $board['id'])

echo '
<tr>
<td class="windowbg2" valign="middle" align="center" width="6%">
<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="" border="0" align="middle" /></td>
<td class="windowbg" valign="middle" width="48%">
' . $topic['first_post']['link'] . ' <a href="' . $scripturl . '?topic=' . $topic['id'] . '.from' . $topic['newtime'] . ';topicseen#new"><img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/new.gif" alt="' . $txt[302] . '" border="0" /></a> <span class="smalltext">' . $topic['pages'] . '</span>
<div class="smalltext"><i>' . $txt['smf88'] . ' ' . $topic['board']['link'] . '</i></div></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="27%">
<span class="smalltext">' . $topic['last_post']['time'] . '<br />' . $txt[525] . ' ' . $topic['last_post']['member']['link'] . '</span></td>
</tr>';
}
}


Admittedly, this is not the very best way to do it, but it is one of the simpler...

-[Unknown]

NoRad

#6
Thank you for this start. It's not fully working though.

http://www.thesilents.org/forum/index.php?action=unreadreplies

You can check it out there. I might adjust the colors of the sub-headers to stand out more.
I've noticed that the categories are not correct for the posts, and I want to remove the category in small text under the topic title since it's no longer needed.

[Unknown]

I don't have an account, so I can't see it..

The boards aren't correct when doing this?  Ah, cripes.  Missed a line.  Getting tired and sloppy, I am.

Find:
if ($topic['board']['id'] != $board['id'])

Replace:
if ($topic['board']['id'] != $board['id'])
   continue;

-[Unknown]

NoRad

Sweet. After making your change I achieved the results I want by removing this line:
<div class="smalltext"><i>' . $txt['smf88'] . ' ' . $topic['board']['link'] . '</i></div>

What do I need to do in order to sort the category headers so that they match the default order on my index.php?

[Unknown]

Hmm, that's a bit more fun... or actually, it isn't really THAT much different, except that it requires changes to source files.

Find this in Sources/Recent.php:
ORDER BY b.boardOrder, ml.ID_MSG DESC

(three times, all in UnreadTopics().)

And make it:
ORDER BY b.boardOrder, ml.ID_MSG DESC

-[Unknown]

NoRad

Login = testuser
pw = test

Incase you wanted to view how it looks... I think it's cleaner than the current method of listing new topics.

NoRad

Just a note for anybody reading this. I think he meant to Find " ORDER BY ml.ID_MSG DESC " and replace it with " ORDER BY b.boardOrder, ml.ID_MSG DESC "

[Unknown]

Quote from: Radianation on September 01, 2004, 01:05:03 AM
Just a note for anybody reading this. I think he meant to Find " ORDER BY ml.ID_MSG DESC " and replace it with " ORDER BY b.boardOrder, ml.ID_MSG DESC "

Ah, yes, I replaced both of them.  I could make an excuse but I won't...

-[Unknown]

NoRad

No excuses needed. You're a like an answering machine  ;) on these forums. You answer damn near every post everytime you sign on. What would we all do without [unknown] ??

I noticed something a little odd btw. When I still had hundreds of unanswered posts it would list several categories on the front page with posts under them, and then on the next page the same (but maybe the categories are in a different order). I anticipated it to list all recent or unanswered posts under the 1st category for several pages, and then do the same with the next category. While this seems kind of cumbersome for somebody with HUNDREDS of unanswered posts, it looks really nice if you only have 20-30 new posts since your last visit. What is causing them to sort like this and span on several pages out of order, even if the initial page is correct?

[Unknown]


NoRad

Trying that now. Looks ok, but I need to make an account with all of the topics still unread =)

firewired

#16
Guys, this is great! Made the changes, and "action=unread" is sorting perfectly. The headers are an elegant touch.

How do I extend this so that it covers "action=unreadreplies"? The headers/separators don't show up. Also, with the current modifications, it sorts by board for the most part. One of the accounts has 7 pages of unreadreplies and the sorting gets messed up in some places: 5 entries from board A, broken by 1 entry from board B, then 3 entries from Board A, etc. etc.

NoRad

I have the same problem if you have a lot of unread replies. I definitely think this layout is easier to read and less cluttered.

mytreo

#18
Thanks everyone. This is an excellent mod, exactly what I was looking for. I totally agree that the display is much easier to read this way, especially for busy or large boards.

1. Tell me, did you settle on "ORDER BY b.boardOrder, ml.ID_MSG DESC" or "ORDER BY b.boardOrder" - when I tried the latter it sorted posts correctly but newest posts were at the bottom and I think I'd prefer them to be at the top?

2. I'm sure if we work together we can apply the same method to the unread replies template :)

3. Also an additional mod I'd like to make will be the ability to selectively mark a board or topic as read directly from the results page, this allows you to quickly filter all topics you're not interested in. I guess there is a function somewhere to mark an individual board/topic as read so this should just be a themeing mod. Hey i'm beginning to like the way that SMF themes, it's groovy 8)

Edit: I just noticed from Subs-Board.php that 3 should be really easy to achieve just through a theme. Wow SMF is clever.

Chris
Treo forum - Powered by SMF, of course
Treo news - powered by MovableType and integrated with SMF
Treo downloads - hacked from phpNuke and integrated with SMF
Treo knowledge base - powered by Wikka and integrated with SMF
Treo 650 | Treo 700w | Treo 700p

NoRad

Now I'm not showing any new posts whenever I hit the site. My users are having the same problem since the upgrade from rc2 to 1.0 ... Is it a theme incompatability issue or maybe the cookies?

Advertisement: