Login  |  Register
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome, Guest. Please login or register.
Did you miss your activation email?

February 05, 2023, 11:23:07 AM

Login with username, password and session length
Members
  • Total Members: 3856
  • Latest: Bixby
Stats
  • Total Posts: 193983
  • Total Topics: 21135
  • Online today: 45
  • Online ever: 3540
  • (September 02, 2022, 06:38:54 PM)
Users Online
Users: 4
Guests: 31
Total: 35

Author Topic: [Block] Article Category Menu list  (Read 13914 times)

0 Members and 1 Guest are viewing this topic.

Stardust

  • Guest
Re: Article Category Menu list
« Reply #30 on: July 19, 2008, 09:52:32 AM »
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

Offline IchBin

  • Friends
  • *
  • Posts: 16231
Re: Article Category Menu list
« Reply #31 on: July 21, 2008, 06:24:50 PM »
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

  • Guest
Re: Article Category Menu list
« Reply #32 on: July 21, 2008, 06:50:29 PM »
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

  • Guest
Re: Article Category Menu list
« Reply #33 on: August 06, 2008, 09:36:49 AM »
I've been toying around with snippits from a variety of posts here and came up with this:

Code: [Select]
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. 

Offline IchBin

  • Friends
  • *
  • Posts: 16231
Re: Article Category Menu list
« Reply #34 on: August 06, 2008, 11:52:20 AM »
Looks nice. I'll link  to it in the first post. Thanks!

Offline Ken.

  • Support Team
  • *
  • Posts: 4363
    • Our FamilyForum
Re: Article Category Menu list
« Reply #35 on: August 06, 2008, 12:52:19 PM »
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.

Offline [chrisB]

  • Jr. Member
  • **
  • Posts: 67
Re: [Block] Article Category Menu list
« Reply #36 on: January 06, 2023, 05:38:57 PM »
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.

Offline @rjen

  • Support Team
  • *
  • Posts: 3487
    • FJR-club Nederland
Re: [Block] Article Category Menu list
« Reply #37 on: January 15, 2023, 09:27:18 AM »
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...

Code: [Select]
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

Offline @rjen

  • Support Team
  • *
  • Posts: 3487
    • FJR-club Nederland
Re: [Block] Article Category Menu list
« Reply #38 on: January 15, 2023, 10:04:23 AM »
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)

Code: [Select]
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

Offline [chrisB]

  • Jr. Member
  • **
  • Posts: 67
Re: [Block] Article Category Menu list
« Reply #39 on: January 15, 2023, 06:37:52 PM »
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. 🙇‍♂️