WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] [Help ]Query with wp_pagenavi?

[Resolved] [Help ]Query with wp_pagenavi?

  • I use this code queries all posts

    <?php
    $paged = get_query_var('paged') ? get_query_var('paged') : 1;
    query_posts(array(
    'post_type' 		=> 'san-pham',							'posts_per_page'	=> 8,
    'paged'			=> $paged,
    'order'			=> 'DESC',
    )
    );
    ?>
    <?php $i=1; while(have_posts()) : the_post(); ?>
    //
    <?php $i++; endwhile ?>
    <?php if (function_exists('wp_pagenavi')) {
    wp_pagenavi(); } ?>

    I want to queries all the posts from each category???? Help me!!!!!

Viewing 15 replies - 1 through 15 (of 38 total)
  • deepbevel
    Member

    @deepbevel

    not sure if this is realted or may help with your issue:
    http://wordpress.org/support/topic/categoryphp-post_types-divided-per-category?replies=7

    Example:
    Category A
    Category B
    Category C
    Category D
    When I click on the Category A it will display all the posts on the Category A and paging (8 posts on one page)
    Help me?

    deepbevel
    Member

    @deepbevel

    does it need to stay on one page? if not, just use category pages, make them with a custom menu (appearance/menus), then display it with the custom menu widget.

    with the above code when I click on Category A,B,C,D.. it will show all products. I am use custom menu and not used queries it does not show 8 products on 1 page although I was setting in the reading in the wp-admin.I want to show 8 posts on the one page when clicking on category A, 8 posts on the one page when clicking on category B,8 posts on the one page when clicking on category C……you understand my problem

    deepbevel
    Member

    @deepbevel

    sorry, not sure, I think you say you are using a custom menu, but are you saying you set 8 posts in settings/reading, but still don’t get 8 posts?
    Do you get paging?

    deepbevel
    Member

    @deepbevel

    thanks for all your answer but I still have not solved the. with the above code it displays all the posts of all categories. I want to display all the posts of one category and 8 posts on the one page

    deepbevel can support yourself? thank you very much

    deepbevel
    Member

    @deepbevel

    I do okay

    deepbevel
    Member

    @deepbevel

    oh, you mean, support you with this, sorry..
    Well, I suppose but at this point I’m confused by your code and the details of the goal.

    If you want to integrate a query with jQuery, I may have difficulty.
    If you want 8 posts from one category, This is how I do it.

    <?php
    	 $args = array(
    				   'cat' => '5',
    				   'post_type' => 'san pham',
    	                              'order' => 'DESC',			                     'posts_per_page' => 8,
    				   'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1)
    				   );
    
    	query_posts($args);
    
    while (have_posts()) : the_post();
    ?>

    You go to their site to understand: girlxinh.asia/wordpress/ . You click category “CAMERA GIÁM SÁT” on the left sidebar. in which the “PIN MÁY ẢNH SONY NP-FT1” not in Category “CAMERA GIÁM SÁT” .it’s on the category “PIN SẠC MÁY ẢNH” . You understand? my english is poor.sorry

    I pass ‘cat’ in the white pages

    deepbevel
    Member

    @deepbevel

    Yes,I was not clear on the goal.
    You need to get any category which is selected from the menu. That’s normal behavior for a category page. But I’m not sure this is a category page, perhaps if you post the entire code here.

    The code for your template includes jQuery, which I no nothing about.

    <?php $i++; endwhile ?>

    I don’t know what the $1++;” means. I’m not even 100% sure it’s jQuery related, but I think so.

    full code

    <?php get_header();?>
    <div class="main-container col2-left-layout">
    	<div class="main">
    		<div class="breadcrumbs">
    		<ul>
    			<?php require_once('breadcrumb.php');?>
    		</ul>
    		</div>
    		<div class="col-main">
    					<div class="home-products" style="margin-top:15px;">
    						<div class="block-title">
    							<strong id="abc">
    								<?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );?>
    								<?php //echo get_the_term_list( $post->ID, 'nhom-hang');
    								echo $term->name
    								?>
    							</strong>
    						</div>
    						<?php
    							if(have_posts() ){
    						?>
    						<ul class="products-grid">
    						<?php	
    
    						$paged = get_query_var('paged') ? get_query_var('paged') : 1;
    						//query_posts('post_type=san-pham&posts_per_page=8&paged='.$paged);
    						query_posts(array(
    							'post_type' 		=> 'san-pham',
    							'posts_per_page'	=> 8,
    							'paged'				=> $paged,
    							'order'				=> 'DESC',
    
    							)
    						);
    						?>
    						<?php $i=1; while(have_posts()) : the_post(); ?>
    						<?php if ($i==1)
    							{echo ' <li class="item first">';}
    							;?>
    							<?php if ($i==2)
    							{echo ' <li class="item">';}
    							;?>
    							<?php if ($i==3)
    							{echo ' <li class="item last">';}
    							;?>
    							<?php if ($i==4)
    							{echo ' <li class="item first">';}
    							;?>
    							<?php if ($i==5)
    							{echo ' <li class="item">';}
    							;?>
    							<?php if ($i==6)
    							{echo ' <li class="item last">';}
    							;?>
    							<?php if ($i==7)
    							{echo ' <li class="item first">';}
    							;?>
    							<?php if ($i==8)
    							{echo ' <li class="item">';}
    							;?>
    							<?php if ($i==9)
    							{echo ' <li class="item last">';}
    							;?>
    								<div class="product-box">
    									<a href="<?php the_permalink();?>" title="<?php the_title();?>" class="product-image">
    										<img src="<?php echo get_post_meta($post->ID, 'image', true); ?>" width="204" height="204" alt="<?php the_title();?>">
    									</a>
    									<h3 class="product-name"><a href="<?php the_permalink();?>" title="<?php the_title();?>"><?php catchuoi_title(35); ?></a></h3>
    								</div>
    								<div class="clear"></div>
    								<div class="price-box">
    									<?php
    									$discount = get_post_meta(get_the_id(), 'discount',true);
    									$price = get_post_meta(get_the_id(), 'price',true);
    									?>
    
    									<?php if (!$discount) {?>
    									<span class="regular-price" id="product-price-1-new">
    										<span class="price"><?php echo get_post_meta($post->ID, 'price', true); ?></span>
    									</span>
    									<?php } ?>
    									<span class="regular-price" id="product-price-1-new">
    										<span class="price"><?php echo get_post_meta($post->ID, 'discount', true).'vnđ'; ?></span>
    									</span>
    
    								</div>
    								<div class="clear"></div>
    								<div class="actions">
    									<?php
    									if(function_exists('addCartButton')){
    									addCartButton(get_the_id(),"Giỏ hàng");
    									}
    									?>
    									<a class="button-view" href="<?php the_permalink();?>" title="View">Chi tiết</a>
    								</div>
    							</li>
    							<?php $i++; endwhile ?>
    						</ul>
    						<?php } else{ ?>
    						<h1>Chưa có sản phẩm!!!!!</h1>
    						<?php } ?>
    					</div>
    					<div style="float:right; margin-top:20px;">
    						<?php if (function_exists('wp_pagenavi')) {
    						wp_pagenavi(); } ?>
    					</div>
    
    		</div>
    		<?php get_sidebar('1');?>
        </div>
    <?php get_footer();?>

    deepbevel
    Member

    @deepbevel

    It looks like you are only getting posts for one of the categories.
    I have to assume all your posts are using the custom taxonomy, and post type, and each is assigned accordingly?

    I’m sorry, I feel like I don’t have enough insight into the nature of the problem, need a better explanation. This is a hard one for me..

Viewing 15 replies - 1 through 15 (of 38 total)
  • The topic ‘[Resolved] [Help ]Query with wp_pagenavi?’ is closed to new replies.