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)
-   -   Display posts alphabetically for one category, chronologically for other categories (http://forum.bytesforall.com/showthread.php?t=1954)

spencer Jun 6, 2009 07:10 PM

Display posts alphabetically for one category, chronologically for other categories
 
I want to display the posts on most of my category pages in reverse chronological order, which is working just fine. But for one category (a glossary of terminology), I would like to display the posts in alphabetical order. I've created a separate category.php file for the glossary, but I can't get the order to change from the order in which I entered the posts. The page in question can be seen at:
http://www.jmek.net/bookbuildersWest...s/?page_id=199.

So far, I've been playing with the following php code in the template page. Is this the right place or should I be elsewhere? What do I need to change (here or elsewhere) to get the posts alphabetized?

if ( $bfa_ata_archives_category_show == "Yes" ) { ?>
<h3><?php echo $bfa_ata_archives_category_title; ?></h3>
<ul>
<?php wp_list_categories('orderby=name&order=asc&title_l i=' .
'&show_count=' . ($bfa_ata_archives_category_count == "Yes" ? '1' : '0') .
'&depth=' . $bfa_ata_archives_category_depth .
($bfa_ata_archives_category_feed == "Yes" ? '&feed_image=' . get_bloginfo('template_directory') . '/images/icons/feed.gif' : '')); ?>
</ul>
<?php } ?>

Spencer

Flynn Jun 10, 2009 05:42 AM

wp_list_categories lists the list of categories, not the list of posts in a category: http://codex.wordpress.org/Template_...ist_categories

You can use get_posts for this: http://codex.wordpress.org/Template_Tags/get_posts

<ul>
<?php
global $post;
$myposts = get_posts('numberposts=10&order=ASC&orderby=title&category=1');
foreach($myposts as $post) :
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>

replace category=1 with the ID of the category you want to pull posts from

To display this on a specific page, create a pagename.php, to display it on a specific category page create a category-ID.php

See http://codex.wordpress.org/File:Template_Hierarchy.png

robdeluxe Nov 18, 2009 04:21 AM

Hi Flynn,

I am trying what you suggested but it is not working. Instead of returning posts for the current category it is returning all posts from all categories. Here is what I have tried...

<ul>
<?php
global $post;
if (is_category( )) {
$cat = get_query_var('cat');
$yourcat = get_category ($cat);
/*echo 'the slug is '. $yourcat->slug;*/

$myposts = get_posts('category=$cat&&numberposts=-1');
foreach($myposts as $post) :
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach;
} ?>
</ul>

I am using wordpress v2.8.4. I think it might be a bug in get_posts?

Have you any ideas?

Thanks,
Rob

dherrenvt Jul 14, 2014 05:34 PM

I would like to do something related. When displaying a post within a particular category (in this case, my "grammar" category), I would like the Next and Previous Post links to display in alphabetical order by post title within just that category.

I found an old, closed, forum post about this topic and a plugin was suggested (WP Post Sorting plugin), but that hasn't been updated for over 2 years and doesn't appear to work with Wordpress 3.9.1 and Atahualpa 3.7.15.

lmilesw Jul 16, 2014 09:01 AM

Perhaps this plugin will work for you.


All times are GMT -6. The time now is 08:41 AM.

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