This code snippet will grab all the titles of Categories and create a list with sub-categories indented. Thanks to Jaybachatero from SMF for the help.
Add this to a phpbox type block.
global $db_prefix, $scripturl;
$request = db_query("
SELECT id, value1, value2
FROM {$db_prefix}tp_variables
WHERE type = 'category'", __FILE__, __LINE__);
$links = array();
while ($row = mysql_fetch_assoc($request))
{
// It's a parent.
if (empty($row['value2']))
$links[$row['id']] = array(
'id' => $row['id'],
'name' => $row['value1'],
'link' => '<a href="' . $scripturl . '?cat=' . $row['id'] . '">' . $row['value1'] . '</a>',
'children' => array()
);
elseif (isset($links[$row['value2']]))
$links[$row['value2']]['children'][$row['id']] = array(
'id' => $row['id'],
'name' => $row['value1'],
'link' => '<a href="' . $scripturl . '?cat=' . $row['id'] . '">' . $row['value1'] . '</a>',
);
}
mysql_free_result($request);
echo '
<ul style="list-style-type: none; margin-left: 0; padding-left: 0;">';
// Loop through the array.
foreach ($links as $link)
{
if (empty($link['children']))
echo '
<li>', $link['link'], '</li>';
else
{
echo '
<li>', $link['link'], '
';
// Indented Child links
// Change margin setting for more indentation if needed.
foreach ($link['children'] as $child)
echo '
<li style="margin-left: 7px">', $child['link'], '</li>';
echo '
</li>';
}
}
echo '
</ul>';
Here's an additional nice looking layout and design of this code posted by Stardust.
http://www.tinyportal.net/index.php?topic=19495.msg203123#msg203123
Great I look forward to applying the code.
Shawn Larson
Looks good thank you.
One thing that would be nice to see in the future is the ability to collapse the subcategories in the categories if that makes any sense. Thanks again for your help!
Well, in order to make the categories upshrink that would either require a database setting stored, or a cookie. Of which, I don't really know how to do atm. :(
We will just leave this up and maybe somebody will have a suggestion. I really need to learn php. I have lots of cool ideas..
Well, doing the upshrink requires javascript. And I know pretty much zero when it comes to javascript.
You could reuse the upshrink code that came with default shirink-ers or implement this
http://www.tinyportalmedia.com/main/index.php/topic,1273.0.html
after Drgoon fixes up some details.
Feel free to do it lebisol. :)
Thanks - great menu - even when made available only to admins makes it easy to access all the artilcles from the homepage. Thanks again
Cheers
Quote from: IchBinâ,,¢ on October 25, 2007, 01:16:49 AM
Feel free to do it lebisol. :)
:) Hey he asked for suggestions ...I will send you a pm if interested.
All the best!
after you select a section how can you make all the articles with no right blocks ??
Not sure what you mean.. The category box just lists categories and subcategories.. Once you click the link it goes the category page with the article listings.
PS Anything on the javascript idea.. Just curious.. It sounded really intriguing.. Thanks!
QuoteNot sure what you mean.. The category box just lists categories and subcategories.. Once you click the link it goes the category page with the article listings.
When you click on a category it brings you to a page with all the articles from that category. But I would like it to show the articles with no side blocks. I did not see an option for this
Each article has visual options.. and 3 of them are whether to display Left, Right or Center blocks.
Would you just have your user just use top navigation or something to get to where ever they need to go after they view article?
Depends on the Article. I have some, like the chat room and other forum features that don't have any navigation, other than the main menu bar.. Help Articles, I display blocks on the left.
Yes if i click on the individual article the blocks go away but when it shows all the articles when you click on the category I would like no side blocks
Zetan it sounds like you can do it. How is it done?
When you see an Article in Admin view, or the edit screen.. each has two option panels.
- [Edit article]
- [Edit options]
[Edit options] is where all the visual options are, like link tree, panels, commenting etc.
Remember though, if you are displaying more than 1 article on say, the home page.. and 1 has left blocks, and the other dosen't, they will conflict.. so both need to ideally be set the same.. One can have comments enabled though, and the other can have comments switched off.
It's generally blocks and article theme settings that can be a problem. No fault of the software, but conflicting visual options can cause confusion.
Ill look threw all the options again thanks
Hey, I'm currently using the navigation script, created by IchBin (It rocks :P) however, I created a new category and 3 new forums and they didn't appear on the Navigation. Well, at least the forums didn't, the category does appear..
Link: RoC.Blizzcraft.Org
For support you should post in the topic where the code is posted. Which forums do not appear? I just looked at your list and it shows the same boards that I can see in the list.
This topic is also posted in the wrong section of the forum.
I will lock this and refer to IchBins thread in the block code and snippets board.
The category "lord of the rings" doesn't show its forums.
Are you talking about this section?
See attachment.
Forgive my ignorance, which type of Box would you put this code into? Scriptbox? PHPBOX?
phpbox block type.
Has anyone ever tweaked this snippet to include the articles themselves?
(I've searched and searched and searched, so please forgive me if I missed where this might have already been posted)
If it had been done I'm sure it would have been posted in this topic. Why would you want a menu style of articles with full body text?
I'm sorry, I wasn't clear.
This script does almost everything I need. I'd like one extra layer to nest the article names.
e.g.
Category
--Article Name
--Article Name
----SubCategory
------Article Name
----SubCategory
------Article Name
Category
--Article Name
Sorry, but the multiple sub categories and articles is a little much on my PHP/MySQL knowledge. This requires some tables joins as well as determining what is a category vs article, and what is a parent vs child. Its pretty difficult. At least for me it is... I'll keep stabbing at it though to see if I can figure it out as I get time.
Well, I appreciate it. It's certainly beyond my abilities (which are next to none ;) )
At any rate, I understand that most everyone on here has enough to do with their real lives without adding to the work pile for all us needy folks. Good luck :)
I've been toying around with snippits from a variety of posts here and came up with this:
global $db_prefix, $scripturl;
$articles = db_query("
SELECT art.subject, art.id, var.value1 AS category_name
FROM {$db_prefix}tp_articles AS art
LEFT JOIN {$db_prefix}tp_variables AS var ON (var.id = art.category) ORDER BY value1
LIMIT 100", __FILE__,__LINE__);
echo '
<table cellspacing="0" cellpadding="0" width="100%" style="margin-top: 4px; margin-bottom: 4px;" border="0" class="tborder">
<tr>
<td>
<ul style="list-style-type: none; margin-left: 0; padding-left: 0;">';
$category = '';
if (mysql_fetch_assoc($articles) == 0)
echo '
No Reviews Available';
else
{
while ($row = mysql_fetch_assoc($articles)){
$category2 = $row['category_name'];
if($category != $category2){
echo'
<li><b><i><u>', $category2 ,'</u></i></b></li>';
$category = $category2;
}
$category3 = $row['category_name'];
if($category3 == $category2){
echo '
<li style="margin-left: 7px"><font size="1"><a href="', $scripturl ,'?page=', $row['id'], '"><b>', $row['subject'], '</b></a></font></li>';
}
}
}
echo '
</ul>
</td>
</tr>
</table>';
mysql_free_result($articles);
It doesn't indent subcategories, but for as few articles as I have, there's not really a need. I apologize if this isn't the appropriate thread to put this in, but it was where I had made my initial inquiry.
Looks nice. I'll link to it in the first post. Thanks!
Just tried it and it works very well. :up:
... had to turn it off though, mine was showing over 50 articles!
Does this still work?
I addded it as a PHPblock but nothing shows, this said I don't have any articles just yet but I would like to show all the categories I intend to post articles too.
Any help would be great appreciated.
Wow, that code was seriously outdated. I assume that was from the SMF1 era, did not work in 2.0 or in 2.1.
I updated the code so it works in SMF2.1. Find the corrected PHP code below.
Warning this code produces a list of articles per category, but it does NOT check to see if the article is published, or if the user actually has permissions to see them.
It may be wise to use this code with caution...
global $smcFunc, $scripturl, $modSettings, $settings, $txt;
// Retrieve the articles.
$request = $smcFunc['db_query']('', '
SELECT art.subject, art.id, var.value1 AS category_name
FROM ({db_prefix}tp_articles AS art)
LEFT JOIN {db_prefix}tp_variables AS var ON (var.id = art.category) ORDER BY value1',);
$articles = array();
while ($row = $smcFunc['db_fetch_assoc']($request)) {
$articles[] = array(
'subject' => $row['subject'],
'id' => $row['id'],
'category_name' => $row['category_name'],
);
}
$smcFunc['db_free_result']($request);
echo '
<ul style="list-style-type: none; margin-left: 0; padding-left: 0;">';
if (empty($articles)) {
echo '
No articles Available';
}
else
$category = '';
foreach ($articles as $article)
{
$category2 = $article['category_name'];
if($category != $category2){
echo'
<li><b><i><u>', $category2 ,'</u></i></b></li>';
$category = $category2;
}
$category3 = $article['category_name'];
if($category3 == $category2){
echo '
<li style="margin-left: 7px"><font size="1"><a href="', $scripturl ,'?page=', $article['id'], '"><b>', $article['subject'], '</b></a></font></li>';
}
}
echo '
</ul>';
Added a select so only active and approved articles are listed, and also a sort in the articles on position (ascending) and date (descending, so newer on top)
global $smcFunc, $scripturl, $modSettings, $settings, $txt;
// Retrieve the articles.
$request = $smcFunc['db_query']('', '
SELECT art.subject, art.id, art.parse, art.date, var.value1 AS category_name
FROM ({db_prefix}tp_articles AS art)
LEFT JOIN {db_prefix}tp_variables AS var ON (var.id = art.category)
WHERE art.approved = 1 and art.off = 0
ORDER BY value1, parse, date DESC',);
$articles = array();
while ($row = $smcFunc['db_fetch_assoc']($request)) {
$articles[] = array(
'subject' => $row['subject'],
'id' => $row['id'],
'category_name' => $row['category_name'],
);
}
$smcFunc['db_free_result']($request);
echo '
<ul style="list-style-type: none; margin-left: 0; padding-left: 0;">';
if (empty($articles)) {
echo '
No articles Available';
}
else
$category = '';
foreach ($articles as $article)
{
$category2 = $article['category_name'];
if($category != $category2){
echo'
<li><b><i><u>', $category2 ,'</u></i></b></li>';
$category = $category2;
}
$category3 = $article['category_name'];
if($category3 == $category2){
echo '
<li style="margin-left: 7px"><font size="1"><a href="', $scripturl ,'?page=', $article['id'], '"><b>', $article['subject'], '</b></a></font></li>';
}
}
echo '
</ul>';
You're a star rjen!
I found the inbuilt menu code a few days ago, it takes me a bit of time to navigate and understand bits. These is a nice addition though. 🙇♂️