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

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,973
  • Latest: NonStop
Stats
  • Total Posts: 196,231
  • Total Topics: 21,353
  • Online today: 606
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 261
  • Total: 261

Category box listing articles by alphabetical order?

Started by animecosmo, February 10, 2007, 11:22:11 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

animecosmo

I was wondering if there was a way to make the category box (or a scriptbox) automatically list articles in a certain category by alphabetical order rather than by date published? I run a role playing game, and I'd like to have the characters listed alphabetically by last name for ease in finding the profiles.

Thanks in advance! TP people respond much faster, and with much better responses to all my questions than people in the regular SMF forum do. You guys are awesome!

JPDeni

You could write a php block or article that would list the articles any way you wanted. It wouldn't be the built-in category box, but you could easily have your own category box set up however you wanted.

animecosmo

Quote from: JPDeni on February 10, 2007, 11:34:45 PM
You could write a php block or article that would list the articles any way you wanted. It wouldn't be the built-in category box, but you could easily have your own category box set up however you wanted.

I know I can do that, but I am hoping to make it automatic so that I don't have to add a new link each time a new character is made. Firstly, I'm likely to forget to add it (LOL), and secondly, it is a lot of extra work that I'd rather not have to do, if possible. :)

I'm assuming (I'm still a PHP infant, so bear with me, please) there must be a way to use the code that makes a category box and just change it to list by article name rather than by date posted.

JPDeni

You can do it automatically if you have a php article or block. It would be like a category box, but a specialized one that you would (or I would, I guess :) ) program to behave exactly the way you want it to.

I'm not talking about an html box that you have to add to yourself. It would update itself.

animecosmo

#4
Oooh, how would I go about doing that? Also, I think I should know this, but how do you get the authour to not show up in said box (or any particular category box?).

JPDeni

QuoteOooh, how would I go about doing that?
You ask me really nice and I'll write the php code for you. ;)

QuoteAlso, I think I should know this, but how do you get the authour to not show up in said box (or any particular category box?).
If you program it yourself (or myself :) ), you can put whatever you want there. Or not put whatever you don't want. So....

You want all the article titles in category number... ? (You'll need to find out what the category number is that you want to include.) You want the titles to be clickable links to the full article. You want the titles to be in alphabetical order.

Anything else? Do you want a bulleted list?

Once you see it, if you take a look at the code, you should be able to figure out how to change the formatting, if you should want to later on.

animecosmo

Would it pretty please be possible for you to write the php code for me? *Big grin* I'd love to learn what exactly it means, too, as I am trying hard to learn PHP on my own. However, there are no classes at my college for it. >_>

I finally figured out what an echo was and how to use it via reading the posts on this site. I was so excited when I wrote my first echo.   ;D (Yes, I'm pathetic. I know.)

I want all the articles in category number um...good question (how do I find that out?), clickable links to the full article, author not shown, titles in alphabetical order, bullets not needed.

You can see how I have everything right now at http://www.animecosmo.com/Forum

Look for the "Magical Tidings" block, and then look just below that. I set the two boxes in question to be viable by guests (normally only viewable by people who are active in the RP) so you can see it.

I feel so embarassed. I've no clue what I am doing, but I am trying very hard to learn. LOL.

JPDeni

#7
The way to learn is to look at things and work with them and study them. One thing at a time. I didn't take any classes, either. It's just a puzzle, really. Figuring out how it's done.

Okay... Do you have any articles in the category now? If not, create the category and create an article and assign it the category so you'll have something to access. It won't be happy if there's nothing there.

It would be nice if the category number were visible, since that's how they're referenced in the database. Do you have access to the database, like through phpMyAdmin? If so, you'll be able to find the category number through there. Look for the table smf_tp_articles and find the article you made for this. Look for the field called "category" and see what number is in that field for the article. If this makes no sense to you after giving it a try, I'll try to give you more explicit instructions.

Anyway, once you have the number, put this in a php block:


global $db_prefix, $scripturl;

$category = 36; // this is where you should put your category number. Make sure you leave in the semi-colon

$query = db_query(
    "SELECT id, subject
     FROM {$db_prefix}tp_articles
     WHERE category = $category
     AND off = 0
     AND approved = 1
     ORDER BY subject", __FILE__, __LINE__);
echo '<div style="height: 150px; overflow: auto; width: 100%;">';
while ($row = mysql_fetch_assoc($query))
  echo '<a href="' . $scripturl . '?page=' . $row['id'] . '">' . $row['subject'] . '</a><br />'; 
echo '</div>';


I tested it and it works fine if you have the category number.

While you're at it, take a look at the code and see what's going on. All it does is say "Go into the database table, pick all the rows that have the category I've selected and put them in alphabetical order by subject. Then go through each one and print it out."

animecosmo

#8
Thank you once again. :)

Is there a way to make it scroll like the category box does, after a certain amount of articles?

JPDeni

I'm sure there is a way to make it scroll, but I don't know how to do it. I think that's a css thing that I've just not used before. I'll ask the other team members in case they're not reading this topic.

This website is proudly hosted on Crocweb Cloud Website Hosting.