WordPress.org

Ready to get started?Download WordPress

Forums

Post on Pages (3 posts)

  1. sirthaddeus
    Member
    Posted 4 years ago #

    Okay previous post most of stuff is figured out.

    But now that I have my post from my "Catalog" category showing up on my "Product Catalog" page, I want to be able to go to the other post in my catalog category.

    Current setup is I have only 3 post showing and this is my code for the page:

    <?php
    /*
    Template Name: Product Catalog
    */
    
    get_header(); ?> <!-- header include -->
    
    <div id="left">
    	<div id="left-top">
    			<h2>Product Catalog</h2>
    		</div><!-- end left-top -->	
    
    		<div class="blog-content">
    			<?php query_posts('cat=3&showposts=3&order=ASC&orderby=post_title'); ?>
    			<?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
    
    			<h2><?php the_title(); ?></h2>
    			<p>
    				<?php the_content(); ?>
    			</p>
    
    			<?php endwhile; ?>
    		</div><!-- end blog-content -->	
    
    			<?php else : ?>
    
                <div class="post" id="post-<?php the_ID(); ?>">
                    <h2><?php _e('Nothing Here'); ?></h2>
                </div>
    
    			<?php endif; ?>
    
    			<div class="catalog-pages">
    
    					<p>
    						<?php previous_posts_link(); ?> &bull; <?php next_posts_link(); ?>
    					</p>
    
    					<p>
    
    					</p>
    
    			</div><!-- end catalog-pages -->
    
    </div><!-- end left -->
    
    <?php get_sidebar(); ?> <!-- sidebar include -->
    
    <?php get_footer(); ?> <!-- footer include -->
    
    </div> <!-- wrap end -->
    </body>
    </html>

    The Problem is that when I click on the Nav links at the bottom it takes me to additional pages, but doesnt show the other post from the catalog category. Just recycles the same 3 post over and over.

    How can I have it so it will go to the next page of the category showing the next 3 post in the category and vice versa?

    Thanks in advance!

  2. Wex
    Member
    Posted 4 years ago #

    Read some things about http://codex.wordpress.org/Template_Tags/query_posts

    => Preserving the Original Query (Pagination etc.)

    By default running query_posts will completely overwrite all existing query variables on the current page. Pagination, categories dates etc. will be lost and only the variables you pass into query_posts will be used.

    If you want to preserve the original query you can merge the original query array into your parameter array:

    global $wp_query;
    query_posts(
    	array_merge(
    		array('cat' => 1),
    		$wp_query->query
    	)
    );

    Except your query will probably look something more like:

    Replace:
    query_posts('cat=3&showposts=3&order=ASC&orderby=post_title');
    With:

    global $wp_query;
    query_posts(
    	array_merge(
    		array(
    			'cat' => 3,
    			'posts_per_page' => 3, // Should work better than showposts
    			'order' => 'ASC',
    			'orderby' => 'post_title'
    		),
    		$wp_query->query
    	)
    );
  3. yahyaayob
    Member
    Posted 4 years ago #

    I got an error.
    Warning: array_merge() [function.array-merge]: Argument #2 is not an array in /home2/singanis/public_html/demosite/wp-content/themes/starkers/english_sos_page.php on line 56

    Please help. My code below:

    .......
    
    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts("paged=$paged");
    ?>
    
    <?php global $more; $more = 0; ?>
    
    <?php global $wp_query;
    query_posts(
    		array_merge(
    				array(
    						'cat' => 10,
    						'posts_per_page' => 3,
    						'order' => 'ASC',
    						'orderby' => 'post_title'
    				),
    				$wp_query->query
    		)
    );
    ?>
    
    <?php if (have_posts()) : ?>
    
    <?php while (have_posts()) : the_post(); ?>
    
    <?php $customFieldName = get_post_meta($post->ID, 'Name', true); ?>
    
    	<div id="votebox"><?php if(function_exists('the_ratings')) { the_ratings(); } ?></div>
    
    <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    
    <div id="post-height-engsos"><div class="alignleft"><?php the_post_thumbnail('index-post-thumbnail'); ?></div>
    
    			<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> by <?php echo $customFieldName; ?>
    
    <p class="cat-tag">CATEGORIES: <?php the_category(', ') ?> | <?php the_tags('TAGGED: ', ', ', ''); ?> | <?php the_time('F jS, Y') ?> | <?php edit_post_link('Edit', '', ' | '); ?>  <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?> <!-- by <?php the_author() ?> --></p>
    
    <div class="more-link"><?php the_content('<br />(READ MORE...)'); ?></div>
    
    </div>
    </div>
    	<?php endwhile; ?>
    
            <?php if (next_posts_link() || previous_posts_link()): ?>
    		<?php next_posts_link('&laquo; Older Entries') ?> | <?php previous_posts_link('Newer Entries &raquo;') ?>
    
            <?php endif ?>
    <?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?>
    
    <?php else : ?>
    
    	<h2>Not Found</h2>
    	<p>Sorry, but you are looking for something that isn't here.</p>
    	<?php get_search_form(); ?>
    
    <?php endif; ?>
    
    ......

    Which part did I do wrong?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.