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

Recent

Welcome to TinyPortal. Please login or sign up.

March 28, 2024, 08:51:52 AM

Login with username, password and session length
Members
Stats
  • Total Posts: 195,104
  • Total Topics: 21,212
  • Online today: 212
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 1
  • Guests: 208
  • Total: 209
  • illori

Article list

Started by Nory, May 01, 2017, 11:29:36 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Nory

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?

Nory

Hello,

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

Somebody can help me, please?

lurkalot

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

Or this one. Articles, simple index

Nory

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...

lurkalot

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. ;)

Nory

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...

lurkalot

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.

Nory

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!

lurkalot

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. ;)


Nory

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.