Viewing 15 replies - 16 through 30 (of 31 total)
  • Thread Starter foochuck

    (@foochuck)

    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 ??

    Thread Starter foochuck

    (@foochuck)

    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?

    Jonas Grumby

    (@ss_minnow)

    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).

    Jonas Grumby

    (@ss_minnow)

    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.

    Thread Starter foochuck

    (@foochuck)

    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); 
    
    ?>

    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).

    Thread Starter foochuck

    (@foochuck)

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

    Thread Starter foochuck

    (@foochuck)

    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(); ?>

    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.

    Thread Starter foochuck

    (@foochuck)

    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(); ?>
    Thread Starter foochuck

    (@foochuck)

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

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

    It’s not working correctly…

    'category__in' => array( $cat )

    category__in will only accept an array..

    Thread Starter foochuck

    (@foochuck)

    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:

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

    Thread Starter foochuck

    (@foochuck)

    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!!!

    Glad you got it figured mate… ??

    To be honest i hadn’t examined your code, i was assuming the problem was with the args.. since there were minor errors there, so i kinda just skipped past the rest…

    Unless you need those variables, or you prefer it, you can just move those numeric values directly into the array… (it’s not necessary to create variables if the value isn’t likely to change)

Viewing 15 replies - 16 through 30 (of 31 total)
  • The topic ‘Display Category Entries in Reverse Order?’ is closed to new replies.