TinyPortal

Development => Resources => Topic started by: Nory on May 01, 2017, 11:29:36 PM

Title: Article list
Post by: Nory on May 01, 2017, 11:29:36 PM
Hello,

Is it possible to display only the list of articles of the same category when clicking on a link that was created in "menu" for example?
Title: Re: Article list
Post by: Nory on May 03, 2017, 05:31:53 PM
Hello,

The goal is to create a page that lists all items in each category ...

Somebody can help me, please?
Title: Re: Article list
Post by: lurkalot on May 03, 2017, 07:15:08 PM
Sorry, I meant to come back to this one the other day but forgot to mark it unread.

Now what about using one of these block codes,

Not sure if this one still works as I haven't tried it. Articles - Sorted, Paginated, Categorized, & Customized (http://www.tinyportal.net/index.php?topic=33195)

Or this one. Articles, simple index (http://www.tinyportal.net/index.php?topic=33208)
Title: Re: Article list
Post by: Nory on May 04, 2017, 09:22:18 PM
Hello,

Thank you for your reply, but these doesn't work.

Is it possible to say me where is the code to creat this block "article in a Category"

I search the same in fact...
Title: Re: Article list
Post by: lurkalot on May 04, 2017, 10:30:33 PM
Quote from: Nory on May 04, 2017, 09:22:18 PM
Hello,

Thank you for your reply, but these doesn't work.

Is it possible to say me where is the code to creat this block "article in a Category"

I search the same in fact...

You mean they don't do what you need, or they actually don't work?  I know the second one I linked you to does work, I use it on two of my sites.  You need (the third one) from this post in that thread, http://www.tinyportal.net/index.php?topic=33208.msg275391#msg275391 The first two codes won't work. ;)
Title: Re: Article list
Post by: Nory on May 05, 2017, 10:40:10 AM
Hello,

That you for your support.  O0

I am a beginner in PHP.

I forgot to say you, I use Tinyportal Responsive Beta!

I tested the second code again, and it crashed the portal.

The third code work (surrounded in green), but it don't do that I want...
In red, this is the list that I would want on a page.

My request:

Category 1:
Artilce 1
Article 2
Article 3
etc

Category 2:
Artilce 4
Article 6
Article 9
etc

Category 3:
Artilce 5
Article 8
etc

I hope it's more clear...
Title: Re: Article list
Post by: lurkalot on May 05, 2017, 06:12:35 PM
Yep, did say use the third one. ;)

Ok so using that code with some of it stripped out, and spaces added, what about something like I just added to the left hand side of my test site? http://cctestsite.info/forums/index.php

I have only added two categories atm, just to test, but you can add as many as you like. You can remove or add elements from that code as you wish.
Title: Re: Article list
Post by: Nory on May 05, 2017, 10:43:06 PM
Hello,

Yessssssss, it's that!!!


Quote// Specify your categories, comma separated if more than one category.
$categories = array(1,3,10);

These the lines of code, this is the category to display, is that?

But for me, the category are text, not number!
Title: Re: Article list
Post by: lurkalot on May 05, 2017, 11:14:59 PM
Quote from: Nory on May 05, 2017, 10:43:06 PM
Hello,

Yessssssss, it's that!!!


Quote// Specify your categories, comma separated if more than one category.
$categories = array(1,3,10);

These the lines of code, this is the category to display, is that?

But for me, the category are text, not number!

OK, to find the category number you need to go to TP Admin > Categories  If you click on the name of one of your categories it should give you the number in the address bar of your browser.

The code I used was from the link I gave you, but I removed some of it. as below.


// Configuration

// Specify your categories, comma separated if more than one category.
$categories = array(1);

// The heading area.

echo '
<div style="text-align: center; border: 1px solid #242526; ">   
   <h3>Category 1</h3>
</div>
<br />';

// Now for the code...
global $scripturl, $db_prefix, $smcFunc;

$request = $smcFunc['db_query']('', '
SELECT id, date, subject, views, shortname
FROM {db_prefix}tp_articles
WHERE category IN ({array_int:cats})
AND off = 0
ORDER BY date DESC',
array('cats' => $categories)
);

while ($row = $smcFunc['db_fetch_assoc']($request))
{
   if ($row['shortname'])
   {
      $pageid = $row['shortname'];
   }
   else
   {
      $pageid = $row['id'];
   }

   echo '
   <tr class="windowbg">
      <td style="padding: 3px 0px 3px 10px"><strong><a href="' , $scripturl, '?page=' , $pageid , '">' , $row['subject'] , '</a></strong></td>
      <td style="padding: 3px 0px 3px 10px">' , date('jS, F Y', $row['date']) , '</td>
      <td align="center" style="padding: 3px 0px 3px 15px">' , $row['views'] , '</td>
   </tr><br><br>
';
}

echo '
</table>';

$smcFunc['db_free_result']($request);



I will just say, I'm not a coder, and pretty clueless when it comes to this stuff. So if you have lots of articles in a category you might need to work out a way to limit how many display in that list.  I haven't worked that out yet. ;)

Title: Re: Article list
Post by: Nory on May 08, 2017, 09:49:50 PM
Hello,

Thank you for your help, that work.

I understand little by little.
I try to modify the code to create the list with the separte categories automaticaly.
Title: Re: Article list
Post by: lurkalot on May 08, 2017, 11:53:45 PM
Quote from: Nory on May 08, 2017, 09:49:50 PM
Hello,

Thank you for your help, that work.

I understand little by little.
I try to modify the code to create the list with the separte categories automaticaly.

OK, you can repeat the code in the block for each category you want to display. Just add one category number to each code.  That will show the categories separately.  ;)
Title: Re: Article list
Post by: Nory on May 09, 2017, 02:51:17 PM
Yes, this is what I would do while waiting to find the right code...
because I have lot of categories!!!   :'(