Topic: Adding 'category' to breadcrumb trail in viewtopic and viewforum

Is there an easy way to add the current category identifier to the bread-crumb navigation in viewtopic.php and viewforum.php?

At the moment, for example, in viewforum.php at the top of the page you see:

'Index >> forum name'

and in viewtopic.php you see:

'Index >> Forum name >>Test post'.

I would like to see this line read, for example in the case of viewtopic.php:

'Index >> Category name >> Forum name >> Test post'.

The category name needn't form a link.

In looking at the code in index.php, where the category names are displayed, the category name is extracted as part of a complex query:

$result = $db->query('SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name, f.forum_desc, f.redirect_url, f.moderators, f.num_topics, f.num_posts, f.last_post, f.last_post_id, f.last_poster FROM '.$db->prefix.'categories AS c INNER JOIN '.$db->prefix.'forums AS f ON c.id=f.cat_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].') WHERE fp.read_forum IS NULL OR fp.read_forum=1 ORDER BY c.disp_position, c.id, f.disp_position', true) or error('Unable to fetch category/forum list', __FILE__, __LINE__, $db->error());

which helps make the string

<?php echo pun_htmlspecialchars($cur_forum['cat_name']) ?>

which is used to display the category name in the HTML of index.php.

However viewforum.php and viewtopic.php don't run the same query and so the same code doesn't display any category name.

Is there an easy way to get this information to display on viewforum and viewtopic?

I mean it's there in index.php and also in the (cached) quickjump box that's already visible on both viewtopic and viewforum.

What I guess I want to avoid is adding another query into those pages to extract the current category name out. Is it floating around somewhere else?

As you can guess, I am not that confident in my PHP smile

Re: Adding 'category' to breadcrumb trail in viewtopic and viewforum

You would have to edit the query to add a join for the categories table

3 (edited by sirena 2007-03-27 12:41)

Re: Adding 'category' to breadcrumb trail in viewtopic and viewforum

Smartys wrote:

You would have to edit the query to add a join for the categories table

Aha. Thanks. I'd rather not add to the existing page query load, if I can avoid it. Unless that will add only a miniscule extra amount, and would be easy to do ...

Since footer.php pulls in the quickjump list (manufactured by includes/cache.php), and that information then gets included in both viewforum and viewtopic, directly or indirectly such a query is already effectively being run at least once (and sometimes twice in the case of index.php), on most punBB pages if they have the quickjump dropdown enabled.

So in the spirit of why buy new when used will do, I am thinking there must be a way to grab the category of the currently displayed page out of the existing quickjump drop down menu, without going back to the database, and display the current category a little bit higher in the page....? 

I am trying to do this to improve the navigational usability of a forum.

When you link to topics directly, or come into a viewtopic or viewforum via a search engine, and people don't come in via index.php, you get plonked directly into a topic or forum with no information anywhere on the page (or in the HEAD <title>) about the category it belongs to. Sometimes this information can be useful to visitors.

I mean it is certainly useful to see categories displayed in index.php, and it is useful to work with them in the Administration area smile, but this information isn't passed down to viewforum or viewtopic by default.

In one forum I am designing, one whole category is a post-only 'Noticeboard' space (items can be posted but not discussed), whereas the other major part of the site comprises 'forums' proper, where discussions on topics are allowed.  People need to quickly know which part of the space they have landed in.

That's the simple concept behind this.

Re: Adding 'category' to breadcrumb trail in viewtopic and viewforum

You can't grab it from the quickjump for various reasons, the most important being that you have no way of knowing what category your specific forum is. Well, that and the fact that the quickjump is included AFTER you need to output the category name, so you don't have access to the query in the right place.

Re: Adding 'category' to breadcrumb trail in viewtopic and viewforum

Smartys wrote:

You can't grab it from the quickjump for various reasons, the most important being that you have no way of knowing what category your specific forum is. Well, that and the fact that the quickjump is included AFTER you need to output the category name, so you don't have access to the query in the right place.

Thanks Smartys. I suspected so.

I may have to bite the bullet and modify an existing query or create a new one, and wear the 0.5% extra page performance and code maintenance overhead smile

Re: Adding 'category' to breadcrumb trail in viewtopic and viewforum

Just do one simple query, or add the join to the other one (as it is said further up).
I have a question though, where do you want the user to go when he clicks on the category name? A new file called showcategory.php or something like that? Or do you just want them to see the name of the category (without making it a link)?

FluxBB - v1.4.8

Re: Adding 'category' to breadcrumb trail in viewtopic and viewforum

Just the plain, un-linked name of the category is all I'm aiming for.

It would be nice if the category was indeed a link that took you to a page that displayed the forums within that category (vBulletin style), but I can live without that.