Wordpress Themes - WP Forum at BFA

Wordpress Themes - WP Forum at BFA (http://forum.bytesforall.com/index.php)
-   Atahualpa 3 Wordpress theme (http://forum.bytesforall.com/forumdisplay.php?f=2)
-   -   Alphabetize posts in a category (http://forum.bytesforall.com/showthread.php?t=913)

paulae Mar 22, 2009 03:29 PM

Alphabetize posts in a category
 
I want to have a category called Local Businesses, and I've used AZ-Index (wonderful plugin!) to create an index of categories of businesses, like Accountants, Clothing, Landscapers, etc. I made a text widget for the left sidebar using the index, only showing on the Business category. In addition, I pasted a list of accountants into a post called Accountants, another list into Clothing, etc.

Now, when you click on the Local Businesses link in the category menu, you are shown the most recent post, which is Dentists, because I put that in after Accountants. You can see it here: http://larchmontgazette.com/wp27/category/biz/

I found in the Wordpress codex (http://codex.wordpress.org/Alphabetizing_Posts) a way to alphabetize the output within a category, using a custom template. I created my-businesses-template.php, and put in their code (in red) thusly:

Code:

<?php
/*
Template Name Posts: My Businesses Template
*/
?>

<?php
global $options;
foreach ($options as $value) {
        if (get_option( $value['id'] ) === FALSE) {
                $$value['id'] = $value['std'];
        } else {
                $$value['id'] = get_option( $value['id'] );
        }
}
if ( is_page() ) { global $wp_query; $current_page_id = $wp_query->get_queried_object_id(); }
?>
<?php get_header(); ?>
<?php // If there are any posts:
$posts = query_posts($query_string .
'&orderby=title&order=asc&posts_per_page=-1');


if (have_posts()) : $postcount == 0; ?>

It's not working. Dentists is still showing up ahead of Clothing, Accountants, etc.

What am I doing wrong? Is it some difference between your index.php, which I used to make my-biz-template.php and the standard WP single post code?

Flynn Mar 23, 2009 08:02 PM

Change

PHP Code:

$posts query_posts($query_string 



to

PHP Code:

query_posts($query_string 


paulae Mar 23, 2009 08:25 PM

Alas, that didn't have any effect, I'm afraid. Dentists is still ahead of Accountants.

I'm supposed to leave out the $ at the beginning?

I also cleared the index cache, if that might have had something to do with it.

*EDIT* OK, I've gone back to the default template (index.php). After I made your change, Flynn, the Accountant, Dentists, Architects, etc., pages disappeared when clicked from the left archive menu. I must have messed up something in the code. Could you paste in the full modified code for index.php to be used as my-businesses-template.php to give me the alphabetized list of posts in the Businesses category? Sorry for being so dense!

Flynn Mar 23, 2009 09:17 PM

I had not seen that you're using this for a category page. Can you use a page (or post) template for a category? I am not sure. Normally you'd use category.php, or, in case of Atahualpa, and since it's only a small change, a conditional comment in index.php. Change in index.php

PHP Code:

<?php // If there are any posts:
if (have_posts()) : $postcount == 0?>

to
PHP Code:

<?php // If there are any posts:
if (is_category('Businesses')) {
     
$posts query_posts($query_string '&orderby=title&order=asc&posts_per_page=-1');

if (
have_posts()) : $postcount == 0?>


paulae Mar 24, 2009 05:20 AM

I'll try this. But yes, I've been using index.php modified as a category page, just renamed with the code at the top that you gave me to use it as a Page page. The word Posts has to be in that code. It was working fine, allowing me to have a banner ad in the body, for instance, that didn't appear on other category pages.

*EDIT* OK, I tried that. No change: http://larchmontgazette.com/wp27/category/biz/ . The posts are listed alphabetically, but in reverse order, I suppose because I posted them in that order. Of course, you usually want the most recent post to be at the top!

To be clear, I've taken the Businesses posts out of the custom template, so they're using index.php now. I've just posted a new one in Businesses, Landscapers. It was at the bottom of the page.

I was wondering about the time stamp. I had posted all of them yesterday, but set the publish date back to Jan. 22, to keep them from appearing on the front page as new posts. I just changed the posting time of day for Dentists, and sure enough, it is now below Landscapers. So the system is still using time instead of alphabet to list the posts in Businesses.

Sorry to be such a bother! I realize I'm asking for a lot more customization than most Atahualpa users probably need. Another payment is on the way. (I think "donation" is the wrong term here, since you are providing a professional service!)

Flynn Mar 24, 2009 01:17 PM

Quote:

Originally Posted by paulae (Post 3506)
*EDIT* OK, I tried that. No change: http://larchmontgazette.com/wp27/category/biz/ . The posts are listed alphabetically, but in reverse order

Change order=asc to order=desc in the code

paulae Mar 24, 2009 01:57 PM

That didn't work either.

By the way, I need to stay out of there for a while. The server guys say there is something wrong with my installation, which is causing very slow loading. They say their other Wordpress customers' sites load much faster. I'm not surprised I did something wrong!

I will let you know what they find out.

berryb Apr 7, 2009 01:48 PM

Hey paulae...

I did a search for alphabetizing posts and AZ-Index was what I was looking for, but thought I'd chime in on your problem.

I've got this working on my site... took some tweaking, but I eventually got it... http://www.rush.tv/category/athletes and its a category page. Hope this helps.

Code:

<?php $posts = query_posts( $query_string . '&orderby=title&order=asc' ); ?>
<?php if( $posts ) : ?>

                <?php foreach( $posts as $post ) : setup_postdata( $post ); ?>

                        <div class="cat-wrapper-athletes">
           
                    <?php if ( get_post_meta($post->ID, 'cat_thumb', true) ) { ?>
               
                <a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><img src="<?php echo get_post_meta($post->ID, "cat_thumb", $single = true); ?>" width="290" height="100" alt="" class="main_cat_img" /></a><?php
                               
                                } ?>
               
                    <div id="cat-info-athletes">
               
                                        <h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
                    <?php the_excerpt(); ?>
                   
                                </div>
           
            </div>

                <?php endforeach; ?>
 
<?php endif; ?>


paulae Apr 7, 2009 04:40 PM

Hi there. Thanks for jumping in. Love the site, by the way. I'm an avid skier but stay on the safe side of extreme!

I confess I don't see where you have the names alphabetized at all. What am I missing?


All times are GMT -6. The time now is 07:01 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.