Customizing SMF > Now Available

Displaying only one Category

<< < (3/9) > >>

Oldiesmann:
Nice. Never thought about doing it that way :)

RicochetPeter:
I looked at 'function theme_linktree()' in index.template.php and I don't see an easy way to do what you did in BoardIndex.template.php.
The line in question is prolly 409:

--- Code: ---echo '<b>', $settings['linktree_link'] && isset($tree['url']) ? '<a href="' . $tree['url'] . '" class="nav">' .
   $tree['name'] . '</a>' : $tree['name'], '</b>';
--- End code ---
after the question mark

The URL that's being linked comes from a variable, $tree['url'], which again comes from $context['linktree']. The
--- Code: ---<a href="' . $tree['url'] . '"
--- End code ---
would need to be replaced by the catogid link you used before, but it must come from $context['category']. I don't know how to do that...

A.M.A:
Please make a backup first.

in /Soucres/Load.php look for:

--- Code: ---'url' => $scripturl . '#' . $board_info['cat']['id'],
--- End code ---
replace with:

--- Code: ---'url' => $scripturl . '?catogid=' . $board_info['cat']['id'],
--- End code ---

RicochetPeter:
kewl. got it. thanx again :-)

mytreo:
Great thread, I needed to do the same and after reading this and messing aorund I have found a way to improve it so I'll share it here with you :)

This new method doesn't just hide the layer it actually changes the database query to only select the category that you want.

Pros:

1) the db query size is only as big as it needs to be, above you are still building ALL the categories into the array, then just hideing them from view
2) works in all browsers
3) the hidden categories disappear completely and no white space remains
4) you don't need to edit the template file

Cons:

1) Not really a con, but you need to edit the boardindex.php file NOT the template file.

How to do it:

Open BoardIndex.php and find the query at the top:


--- Code: --- // Find all boards and categories, as well as related information.
$result_boards = db_query("
SELECT
c.name AS catName, c.ID_CAT, b.ID_BOARD, b.name AS boardName, b.description,
b.numPosts, b.numTopics, b.ID_PARENT,
IFNULL(mem.memberName, m.posterName) AS posterName, m.posterTime, m.subject, m.ID_TOPIC,
IFNULL(mem.realName, m.posterName) AS realName," . (!$user_info['is_guest'] ? "
(IFNULL(lb.logTime, 0) >= b.lastUpdated) AS isRead, c.canCollapse,
IFNULL(cc.ID_MEMBER, 0) AS isCollapsed" : ' 1 AS isRead') . ",
IFNULL(mem.ID_MEMBER, 0) AS ID_MEMBER, m.ID_MSG,
IFNULL(mem2.ID_MEMBER, 0) AS ID_MODERATOR, mem2.realName AS modRealName
FROM {$db_prefix}categories AS c, {$db_prefix}boards AS b
LEFT JOIN {$db_prefix}messages AS m ON (m.ID_MSG = b.ID_LAST_MSG)
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = m.ID_MEMBER)" . (!$user_info['is_guest'] ? "
LEFT JOIN {$db_prefix}log_boards AS lb ON (lb.ID_BOARD = b.ID_BOARD AND lb.ID_MEMBER = $ID_MEMBER)
LEFT JOIN {$db_prefix}collapsed_categories AS cc ON (cc.ID_CAT = c.ID_CAT AND cc.ID_MEMBER = $ID_MEMBER)" : '') . "
LEFT JOIN {$db_prefix}moderators AS mods ON (mods.ID_BOARD = b.ID_BOARD)
LEFT JOIN {$db_prefix}members AS mem2 ON (mem2.ID_MEMBER = mods.ID_MEMBER)
WHERE $user_info[query_see_board]
AND b.ID_CAT = c.ID_CAT
AND b.childLevel <= 1
ORDER BY c.catOrder, b.childLevel, b.boardOrder", __FILE__, __LINE__);

--- End code ---

replace with our new query:


--- Code: --- // Find all boards and categories, as well as related information.
$result_boards = db_query("
SELECT
c.name AS catName, c.ID_CAT, b.ID_BOARD, b.name AS boardName, b.description,
b.numPosts, b.numTopics, b.ID_PARENT,
IFNULL(mem.memberName, m.posterName) AS posterName, m.posterTime, m.subject, m.ID_TOPIC,
IFNULL(mem.realName, m.posterName) AS realName," . (!$user_info['is_guest'] ? "
(IFNULL(lb.logTime, 0) >= b.lastUpdated) AS isRead, c.canCollapse,
IFNULL(cc.ID_MEMBER, 0) AS isCollapsed" : ' 1 AS isRead') . ",
IFNULL(mem.ID_MEMBER, 0) AS ID_MEMBER, m.ID_MSG,
IFNULL(mem2.ID_MEMBER, 0) AS ID_MODERATOR, mem2.realName AS modRealName
FROM {$db_prefix}categories AS c, {$db_prefix}boards AS b
LEFT JOIN {$db_prefix}messages AS m ON (m.ID_MSG = b.ID_LAST_MSG)
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = m.ID_MEMBER)" . (!$user_info['is_guest'] ? "
LEFT JOIN {$db_prefix}log_boards AS lb ON (lb.ID_BOARD = b.ID_BOARD AND lb.ID_MEMBER = $ID_MEMBER)
LEFT JOIN {$db_prefix}collapsed_categories AS cc ON (cc.ID_CAT = c.ID_CAT AND cc.ID_MEMBER = $ID_MEMBER)" : '') . "
LEFT JOIN {$db_prefix}moderators AS mods ON (mods.ID_BOARD = b.ID_BOARD)
LEFT JOIN {$db_prefix}members AS mem2 ON (mem2.ID_MEMBER = mods.ID_MEMBER)
WHERE $user_info[query_see_board]
" . (isset($_REQUEST['catogid']) ? "
AND c.ID_CAT = {$_REQUEST['catogid']}" : '') . "
AND b.ID_CAT = c.ID_CAT
AND b.childLevel <= 1
ORDER BY c.catOrder, b.childLevel, b.boardOrder", __FILE__, __LINE__);

--- End code ---

That's all!!  Just point at index.php?catogid=X where X is the category you wish to view :D

Example here: Just see the Star Developer Category at mytreo.net (catogid=4)

You can add links to the pages in the same way as you did above by editing the template file, or also by using that clever trick above in Load.php to change the linktree.

Hope someone else finds this useful. :)

Chris

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version