ThemeShaper Forums » Thematic

[closed]

previous link in category showing same current posts

(10 posts)
  • Started 8 years ago by lastraw
  • Latest reply from helgatheviking
  • This topic is resolved
  1. I think I remember seeing the answer to this here somewhere but can't find it. Here is an example on my test site: http://www.dingdongnation.com/category/life/ (sorry takes a long time to load) at the bottom older posts goes to a page 2 but it's the same posts as page 1

    Posted 8 years ago #
  2. middlesister
    Member

    I think the solution was about filtering the query so that the pagination bit is not overwritten

    global $wp_query;
    $args = array_merge( $wp_query->query, array( 'cat'=>3 ) );
    query_posts( $args );
    Posted 8 years ago #
  3. Thanks middle sister (5 months later!) but I'm not sure how this would integrate with the code that's there now?

    <?php
    
        // calling the header.php
        get_header();
    
    ?>
    
    <div id="box-wide">
    <?php query_posts('category_name=life'); ?>
    
    <?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
    
    <div class="post">
    
    <h3><a>"><?php the_title(); ?></a></h3>
    
    <div class="entry">
    
    <?php the_content(); ?>
    
    </div>
    
    </div>
    
    <?php endwhile; ?>
    <?php endif; ?>
    
    <div class="navigation">
    
    <?php global $wp_query; $total_pages = $wp_query->max_num_pages; if ( $total_pages > 1 ) { ?>
    				<div id="nav-below" class="navigation">
    					<div class="nav-previous"><?php next_posts_link(__( '<span class="meta-nav">&larr;</span> Older posts' )) ?></div>
    					<div class="nav-next"><?php previous_posts_link(__( 'Newer posts <span class="meta-nav">&rarr;</span>' )) ?></div>
    				</div><!-- #nav-below -->
    <?php } ?>		
    
    </div>
    
    </div>
    
    <?php get_footer(); ?>
    
    </body>
    
    </html>
    Posted 8 years ago #
  4. @laststraw - is that a page template? what are you trying to do? is this loop a second query?

    though my first guess is you need to reset the query with

    wp_reset_query();

    after you're done w/ it

    Posted 8 years ago #
  5. middlesister
    Member

    If you give a string to query_posts, then in order to keep your pagination bit replace the query_posts call with

    query_posts( $query_string . '&category_name=life' );

    If you don't keep the query string, then the loop won't know which page you are on and always give you the first posts. Using the array variant I gave above would be

    global $wp_query;
    $args = array_merge( $wp_query->query, array( 'category_name'=>'life' ) );
    query_posts( $args );

    These snippets are equivalent and go above the loop.

    Posted 8 years ago #
  6. Thanks, it's a category template and works now with

    <?php 
    
    		// posts from category 'life'
    		global $wp_query;
    		$args = array_merge( $wp_query->query, array( 'category_name'=>'life' ) );
    		query_posts( $args );
    		if(have_posts()) :
    		while(have_posts()) : the_post(); 
    
    		?>
    
            <div class="post">
    
                <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
    
                    <div class="entry">
    
                        <?php the_content(); ?>
    
                    </div><!-- #entry -->
    
            </div><!-- #post -->
    
    		<?php endwhile; ?>
    
    		<?php endif; ?>
    
            	<div class="navigation">
    
    			<?php posts_nav_link(); ?>
    
                </div><!-- #navigation -->

    It works, but is it "right"?

    Posted 8 years ago #
  7. middlesister
    Member

    Hm, if it is a category template then why are you using query_posts?
    You can just make a file named category-life.php and it will be used on that category.

    Posted 8 years ago #
  8. yup, that's template hierarchy: http://codex.wordpress.org/Template_Hierarchy#Category_display

    but from what you've posted it doesn't look like you are doing enough to warrant a template. if you are just switching this category to show the full post instead of excerpts you can filter thematic_content()

    what are you trying to do precisely?

    Posted 8 years ago #
  9. OK, thanks, that makes sense. Mostly here I'm just trying to understand how category-x.php works. This was an early attempt to display posts from different categories w/different page layouts and sidebars, which I do now with page templates and css. Especially now that /%category%/%postname%/ works in the permalinks with multiple pages (I dislike having /category/ in the URL).

    Posted 8 years ago #
  10. don't use page templates for something category templates will do. you can ditch that /category/ slug in your URL w/ some htaccess trickery. yoast's Wordpress SEO plugin will do it w/ a click.

    Posted 8 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.