TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

October 16, 2024, 01:59:39 AM

Login with username, password and session length
Members
Stats
  • Total Posts: 195,395
  • Total Topics: 21,244
  • Online today: 123
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 0
  • Guests: 46
  • Total: 46

[Block] Article Category Menu list

Started by IchBin, October 21, 2007, 05:22:59 AM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

Stardust

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

IchBin

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.

Stardust

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 :)

Stardust

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. 

IchBin

Looks nice. I'll link  to it in the first post. Thanks!

Ken.

Just tried it and it works very well.  :up:
... had to turn it off though, mine was showing over 50 articles!
" If everything seems under control, you're not going fast enough." - Mario Andretti
Yesterday When I was Young.

[chrisB]

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.

@rjen

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>';
Running Latest TP on SMF2.1 at: www.fjr-club.nl

@rjen

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>';
Running Latest TP on SMF2.1 at: www.fjr-club.nl

[chrisB]

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. 🙇‍♂️