Topic: Alphabetizing Posts by Category

0 Members and 1 Guest are viewing this topic.

April 23, 2009, 07:00 PM

Offline danny

  • Newbie
  • *
  • Posts: 11
    • View Profile
I am trying to alphabetize the posts in ALL categories.  I was reading this in WP Codex:

http://codex.wordpress.org/Alphabetizing_Posts

I am looking at com_wordpress/wp-includes/category.php.  Is this the correct file?  Where should I place the code in order for this to function?  From WP Codex:

Quote
For example, say you have a category named "Glossary" that serves as (obviously) a glossary, where each post is a definition of a specific term, and each term is used as the post title. You want one master list of all the terms, plus their definitions. Edit your theme's category.php file, and make the following changes, just before The Loop:

Code: [Select]
<?php
get_header
();
?>


<div id="content">

<?php
// we add this, to show all posts in our
// Glossary sorted alphabetically
if (is_category('Glossary')) 
{
     
$posts query_posts($query_string 
'&orderby=title&order=asc&posts_per_page=-1');

// here comes The Loop!
if (have_posts()) : while (have_posts()) : the_post(); ?>


« Last Edit: April 23, 2009, 07:10 PM by danny »

April 30, 2009, 05:49 PM

Offline danny

  • Newbie
  • *
  • Posts: 11
    • View Profile
Still looking for a solution here...  This can't be too hard, can it?  A little help..?   ???

May 05, 2009, 08:11 AM

Offline Rafael Corral

  • Administrator
  • Sr. Member
  • *****
  • Posts: 320
    • View Profile
You need to edit the category.php file if I understand correctly from their docs.
Which is normally located here:
/images/wordpress/themes/default/category.php

then you need to put this:
$posts = query_posts($query_string .
'&orderby=title&order=asc&posts_per_page=-1');

at the right spot of the file, the only reason why you would do is_category() is if you only want it for a specific category.

-Rafael

May 05, 2009, 09:16 AM

Offline danny

  • Newbie
  • *
  • Posts: 11
    • View Profile
Cool!  Thanks Rafael.  My partner is working on the site right now, but I will give this a shot when it's is back in my hands.
 :)

May 13, 2009, 11:51 PM

Offline danny

  • Newbie
  • *
  • Posts: 11
    • View Profile
Rafael,

I do have this directory, but there is no category.php in it...
/images/wordpress/themes/default/

The only file that i can find that may be the one I need to edit is in...
components/com_wordpress/wp-includes/   There I have a category.php and a category-template.php

I tried adding your code to both files, and it had no effect.  Am I missing a file in the default theme directory?  I don't think so...  So,  I am still confused about whether I am editing the correct file or not.  And if so, I do not know exactly where to put the code...   ???

Can you show some love and help a guy out?  Thanks, man.

May 23, 2009, 01:34 PM

Offline Rafael Corral

  • Administrator
  • Sr. Member
  • *****
  • Posts: 320
    • View Profile
danny,

I appologize I believe that when a category displays in wordpress it users one of these two template files:
archive.php
archives.php

It is one of those two under the template folder.

May 26, 2009, 12:14 AM

Offline danny

  • Newbie
  • *
  • Posts: 11
    • View Profile
Rafael,

I am getting closer, but there is still an issue.  I believe the correct file is archive.php.  I successfully added the code and also this code:

Code: [Select]
<?php if (is_category()) { $posts query_posts($query_string '&orderby=title&order=asc'); } ?>
I was able to alphabetize the posts, but for some reason instead of just the category posts showing up, ALL posts show up in every category.  I tried pretty much every way possible, but this happens every time.  Any other suggestions?  ???

May 29, 2009, 09:57 AM

Offline Rafael Corral

  • Administrator
  • Sr. Member
  • *****
  • Posts: 320
    • View Profile
Try this, you just need to change the cat number.

Code: [Select]
<?php if (is_category()) { $posts query_posts($query_string '&orderby=title&order=asc&cat=3'); } ?>