WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Display Category Entries in Reverse Order? (32 posts)

  1. foochuck
    Member
    Posted 4 years ago #

    Hello All!

    I would like to display the results on my category page from old to new. Currently it displays posts from new to old. Here is the category page:

    http://www.sopranos.foochuck.com/category/episode-guide/season-1/

    I'm curious as to whether this will effect the entries on my main page, which I do want to continue to display from new to old:

    http://www.sopranos.foochuck.com/

    FYI I'm using a modified version of the Elegant Grunge theme.

    Any help on this would be appreciated.

    Thanks!

  2. Jonas Grumby
    Member
    Posted 4 years ago #

  3. ronchicago
    Member
    Posted 4 years ago #

    there are very robust plugins that will manage categories. i can't vouch for any personally, sorry, but i researched quite a few several months ago that sounded good.

    http://wordpress.org/extend/plugins/search.php?q=category+manager&sort=

  4. Jonas Grumby
    Member
    Posted 4 years ago #

    I think the question was how to reverse the order of posts on category archive pages.

  5. foochuck
    Member
    Posted 4 years ago #

    SS_Minnow : Can I pass one of those variables to my category URL?

    http://www.sopranos.foochuck.com/category/episode-guide/season-1/

    I'm asking because the link that goes to that URL is setup through an add on to my pages section.

  6. foochuck
    Member
    Posted 4 years ago #

    SS_Minnow: It looks like what you sent isn't what I'm looking for.

    On this page:

    http://www.sopranos.foochuck.com/category/episode-guide/season-1/

    I want the posts that show on that page to show from oldest to newest. By default it shows the newest posts first.

    How can I change that just on this specific category page?

  7. Jonas Grumby
    Member
    Posted 4 years ago #

    I don't think the variables can be added to the URL, or at least I have never seen it done that way.

    Are you saying that you have your menu hard-coded so that one of the links can actually display a category archive? Another way to do that is with the Page of Posts page template. Then your Pages menu would not have to be hard-coded.

  8. foochuck
    Member
    Posted 4 years ago #

    SS_Minnow - See my previous post. I'm not trying to change the order of the menu - but rather the posts that show up on my categorys page.

  9. Jonas Grumby
    Member
    Posted 4 years ago #

    Yeah, use the Page Template.

  10. foochuck
    Member
    Posted 4 years ago #

    SS_Minnow : Won't that effect my homepage as well though? I would just like to customize the appearance on the category results page.

  11. Jonas Grumby
    Member
    Posted 4 years ago #

    p.s. I didn't say anything about changing the order of the menu and have no idea where you got that inference from. What I said is that IF your menu is hard-coded for this reason, it doesn't have to be.

  12. foochuck
    Member
    Posted 4 years ago #

    Sorry for my confusion. I'm going to describe this again...

    On this page:

    http://www.sopranos.foochuck.com/category/episode-guide/season-1/

    It displays 9 blog posts that are associated with the 'season 1' category. The posts on this page are displayed from the newest post at the top, down to the oldest post at the bottom.

    I would like to reverse that listing so that the oldest posts in the category are shown at the top of the page and the newest posts show up at the bottom of the page.

    I only want this change to show up on specific categories and not all of my blog pages (for example, newest to oldest works fine on my blog's homepage).

    I understand I may need to customize something or install a plug-in to get this to work, so I'm asking where to start and if anyone knows of a solution to this?

    Thanks!

  13. Jonas Grumby
    Member
    Posted 4 years ago #

    Um, I think you should use the Page Template and assign the template to the pages that you want to do this to. I don't know why you don't seem to want to do this, but it would/could do exactly what you want.

  14. foochuck
    Member
    Posted 4 years ago #

    SS_Minnow : I'm not sure I understand the process you are describing. Could you show me a sample or a tutorial for what you are advising?

  15. foochuck
    Member
    Posted 4 years ago #

    I think I understand what you are saying to do now - create a template for this as a php file and then apply that template to a new page that I create, correct?

    I have never created a page template and have a few questions:

    1. I'm guessing I can just upload the new page I create to my theme folder and it will show up in the WordPress Editor

    2. For the page that I create as a template, how do I pass the variable to it of which category I want it to display? From there I can figure out the other options from the link you first sent - http://codex.wordpress.org/Template_Tags/wp_list_categories

    Thanks

  16. Jonas Grumby
    Member
    Posted 4 years ago #

    Page of Posts page template.

    Here are two pages done this way. Although they are not in reverse order it would have been easy enough to do that if the client wanted it.

    http://prestonsbeat.com/blog/events-calendar/

    http://prestonsbeat.com/blog/newsletter/

    Instead of having a link that points to a category, you create a page (or pages) and assign the template to it (or them).

  17. foochuck
    Member
    Posted 4 years ago #

    Sorry SS_Minnow - I'm a bit slow today ;)

    I think everything you posted is making sense to me now. I appreciate your help and again apologize for the 'internet forum' confusion :)

  18. foochuck
    Member
    Posted 4 years ago #

    I have one last question for you (I hope!):

    I can create a new template page, no problem. The only question or reference material I need:

    What is the PHP code I put on the page to display a specific category post and where can I find the category ID to plug into that PHP?

  19. Jonas Grumby
    Member
    Posted 4 years ago #

    That's ok. Sometimes thoughts don't translate well for various reasons. That is how you would do it though. You can put the order and orderby variables into the template. The template is basically the same as your others (like page.php or index.php) except with that code replacing all of the code in the loop area of the original template (and you have to give your template a name).

  20. Jonas Grumby
    Member
    Posted 4 years ago #

    If you just want to display one post you can use query_posts

    To get the ID of a post, page, or category, pass your mouse over the Edit link in admin. The ID will be in the link.

  21. foochuck
    Member
    Posted 4 years ago #

    Okay so my cat_ID is 10.

    How would I work that into this block of code:

    <?php
    // page id 21 will get category ID 12 posts, page 16 will get category 32 posts, page 28 will get category 17 posts
    if (is_page('21') ) {
    $cat = array(12);
    } elseif ( is_page('16') ) {
    $cat = array(32);
    } elseif ( is_page('28') ) {
    $cat = array(17);
    } else {
    $cat = '';
    }
    
    $showposts = -1; // -1 shows all posts
    $do_not_show_stickies = 1; // 0 to show stickies
    $args=array(
       'category__in' => $cat,
       'showposts' => $showposts,
       'caller_get_posts' => $do_not_show_stickies
       );
    $my_query = new WP_Query($args); 
    
    ?>
  22. Mark / t31os
    Moderator
    Posted 4 years ago #

    Add the order parameter to the args array..

    $args=array(
       'category__in' => $cat,
       'order' => asc,
       'posts_per_page' => $showposts,
       'caller_get_posts' => $do_not_show_stickies
       );

    Also changed the showposts line to posts_per_page to, showposts is or will be deprecated at some point and is replaced by posts_per_page (ultimately your showposts value ends up getting passed to posts_per_page now anyway).

  23. foochuck
    Member
    Posted 4 years ago #

    t31os_ : Would I simply set the $cat variable to 10 (the cat_ID I want to display)?

  24. foochuck
    Member
    Posted 4 years ago #

    I have updated the code to this:

    <?php
    $cat = 10;
    
    $showposts = -1; // -1 shows all posts
    $do_not_show_stickies = 1; // 0 to show stickies
    $args=array(
       'category__in' => $cat,
       'posts_per_page' => $showposts,
       'caller_get_posts' => $do_not_show_stickies,
       'order' => 'DESC'
       );
    $my_query = new WP_Query($args); 
    
    ?>

    Followed by:

    <?php if( $my_query->have_posts() ) : ?>
    
    		<?php while ($my_query->have_posts()) : the_post(); ?>
  25. Mark / t31os
    Moderator
    Posted 4 years ago #

    Assuming you want that specific category yes..

    The order might be wrong however, DESC implies(i think) newest(latest) first, then descending downward(older) then after... ASC should imply(again i think) oldest first, then ascending from there(newer).

    NOTE: I don't believe the order value necessarily need be in uppercase, lowercase should be fine.

  26. foochuck
    Member
    Posted 4 years ago #

    I tried that code and it processed a page that kept looping and all of the content was blank. Here's my whole template page:

    <?php
    /*
    Template Name: Seasons
    */
    
    get_header(); ?>
    <div id="content-container">
    
    <div id="content">
    
    	<div id="body">
    
    <?php
    $cat = 10;
    
    $showposts = -1; // -1 shows all posts
    $do_not_show_stickies = 1; // 0 to show stickies
    $args=array(
       'category__in' => $cat,
       'posts_per_page' => $showposts,
       'caller_get_posts' => $do_not_show_stickies,
       'order' => 'asc'
       );
    $my_query = new WP_Query($args); 
    
    ?>
    
    	<?php if( $my_query->have_posts() ) : ?>
    
    		<?php while ($my_query->have_posts()) : the_post(); ?>
    
    			<div class="post" id="post-<?php the_ID(); ?>">
    
    				<div class="date">
    					<span class="month"><?php the_time('M') ?></span>
    					<span class="day"><?php the_time('j') ?></span>
    					<span class="year"><?php the_time('Y') ?></span>
    				</div>
    
    				<h3><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'elegant-grunge'), get_the_title()); ?>"><?php the_title(); ?></a></h3>
    
    				<?php if ( get_option("show_author") ) : ?>
    				<div class="author"><?php the_author() ?></div>
    				<?php endif ;?>
    
    				<!-- <div class="info">by <?php the_author() ?></div> -->
    
    				<div class="entry">
    					<small><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'elegant-grunge'), get_the_title()); ?>"><?php the_excerpt(__('Continue reading', 'elegant-grunge')); ?></a></small>
    				</div>
    
    				<div class="clear"></div>
    
    				<p class="metadata">
    					<?php comments_popup_link(__('no comments', 'elegant-grunge'), __('1 comment', 'elegant-grunge'), __('% comments', 'elegant-grunge')); ?>
    					<!-- <?php the_tags('&nbsp;&nbsp;|&nbsp;&nbsp;'.__('tags:', 'elegant-grunge').' ', ', ', ''); ?> -->
    					<?php if ( count(($categories=get_the_category())) > 1 || $categories[0]->cat_ID != 1 ) : ?>
    					 | <?php _e('posted in', 'elegant-grunge')?> <?php the_category(', ') ?>
    					<?php endif; ?>
    					<?php edit_post_link(__('Edit', 'elegant-grunge'), '&nbsp;&nbsp;|&nbsp;&nbsp;', ''); ?>
    				</p>
    
    			</div>
    
    			<div class="hr"><hr /></div>
    
    		<?php endwhile; ?>
    
    		<div class="navigation">
    			<div class="next"><?php next_posts_link(__('&laquo; Older Entries', 'elegant-grunge')) ?></div>
    			<div class="previous"><?php previous_posts_link(__('Newer Entries &raquo;', 'elegant-grunge')) ?></div>
    		</div>
    
    	<?php else : ?>
    
    		<h2 class="center"><?php _e('Not Found', 'elegant-grunge') ?></h2>
    		<p class="center"><?php _e('Sorry, but you are looking for something that isn\'t here.', 'elegant-grunge') ?></p>
    		<?php include (TEMPLATEPATH . "/searchform.php"); ?>
    
    	<?php endif; ?>
    
    	</div>
    
    	<?php if ( get_option('page_setup') != 'no-sidebar'  ) get_sidebar(); ?>
    
    </div>
    <div class="clear"></div>
    </div>
    
    <?php get_footer(); ?>
  27. foochuck
    Member
    Posted 4 years ago #

    Here's a link to the page that was generated by that code:

    http://www.sopranos.foochuck.com/the-test-page/

    It's not working correctly...

  28. Mark / t31os
    Moderator
    Posted 4 years ago #

    'category__in' => array( $cat )

    category__in will only accept an array..

  29. foochuck
    Member
    Posted 4 years ago #

    Updated the code:

    <?php
    $cat = 10;
    $showposts = -1; // -1 shows all posts
    $do_not_show_stickies = 1; // 0 to show stickies
    $args=array(
       'category__in' => array( $cat ),
       'posts_per_page' => $showposts,
       'caller_get_posts' => $do_not_show_stickies,
       'order' => 'asc'
       );
    $my_query = new WP_Query($args); 
    
    ?>

    But the same result:

    http://www.sopranos.foochuck.com/the-test-page/

  30. foochuck
    Member
    Posted 4 years ago #

    Just figured it out, was missing: $my_query-> before the_post on this line:

    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>

    Thanks all!!!

Topic Closed

This topic has been closed to new replies.

About this Topic