WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] [Help ]Query with wp_pagenavi? (39 posts)

  1. cannabjs
    Member
    Posted 1 year ago #

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

  2. deepbevel
    Member
    Posted 1 year ago #

    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

  3. cannabjs
    Member
    Posted 1 year ago #

    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?

  4. deepbevel
    Member
    Posted 1 year ago #

    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.

  5. cannabjs
    Member
    Posted 1 year ago #

    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

  6. deepbevel
    Member
    Posted 1 year ago #

    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?

  7. deepbevel
    Member
    Posted 1 year ago #

  8. cannabjs
    Member
    Posted 1 year ago #

    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

  9. cannabjs
    Member
    Posted 1 year ago #

    deepbevel can support yourself? thank you very much

  10. deepbevel
    Member
    Posted 1 year ago #

    I do okay

  11. deepbevel
    Member
    Posted 1 year ago #

    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();
    ?>
  12. cannabjs
    Member
    Posted 1 year ago #

    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

  13. cannabjs
    Member
    Posted 1 year ago #

    I pass 'cat' in the white pages

  14. deepbevel
    Member
    Posted 1 year ago #

    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.

  15. cannabjs
    Member
    Posted 1 year ago #

    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();?>
  16. deepbevel
    Member
    Posted 1 year ago #

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

  17. cannabjs
    Member
    Posted 1 year ago #

    i use

    query_posts(array(
       'post_type' 		=> 'san-pham',						                                                  'posts_per_page'	=> 8,
       'paged'				=> $paged,
       'order'				=> 'DESC',
       'tax_query' => array(										     array(																						'taxonomy' => 'nhom-hang',											'field' => 'slug',											'terms' => get_queried_object()->slug										)									)
    )
    );

    pagenavi ok. But it does get post_per_page = 8 it only show 5 posts

  18. cannabjs
    Member
    Posted 1 year ago #

    i use

    query_posts(array(
    							'post_type' 		=> 'san-pham',
    							'posts_per_page'	=> 8,
    							'paged'				=> $paged,
    							'order'				=> 'DESC',
    							'tax_query' => array(
    										array(
    											'taxonomy' => 'nhom-hang',
    											'field' => 'slug',
    											'terms' => get_queried_object()->slug
    										)
    									)
    							)
    						);

    pagenavi ok. But it does get post_per_page = 8 it only show 5 posts

  19. deepbevel
    Member
    Posted 1 year ago #

    I'm seeing 8 posts

  20. deepbevel
    Member
    Posted 1 year ago #

    I saw 8 posts, with paging working. But it's changing because you are working on it.

  21. cannabjs
    Member
    Posted 1 year ago #

    it shows 8 posts but show all the posts that do not follow any one category

  22. deepbevel
    Member
    Posted 1 year ago #

    are you sure all the posts are using the 'nhom-hang' taxonomy?

  23. cannabjs
    Member
    Posted 1 year ago #

    I am sure

  24. cannabjs
    Member
    Posted 1 year ago #

    Say this as easy to understand.
    I have three category using custom post type(category A,category B, category C)
    When I click on the category A it will display 8 products and paging
    When I click on the category B it will display 8 products and paging
    When I click on the category C it will display 8 products and paging

  25. cannabjs
    Member
    Posted 1 year ago #

    headache with this problem :(

  26. deepbevel
    Member
    Posted 1 year ago #

    Have you tried another theme to test?, I think maybe there's nothing wrong with your code. Maybe a jQuery conflict with a plugin?

  27. cannabjs
    Member
    Posted 1 year ago #

    it does not filter posts by category, when I begin 'cat' => white 12 in query_posts: white page

  28. deepbevel
    Member
    Posted 1 year ago #

    I think I understand, but there could still be a Jquery conflict with the theme or a plugin that makes the filter not work.

  29. cannabjs
    Member
    Posted 1 year ago #

    I use themes estore and use only plugin wp_pagenavi hjxxxxx. thank you for all

  30. deepbevel
    Member
    Posted 1 year ago #

    You might try disabling the plugin, just to check.

    looks like estore is a premium theme. Have you tried to get support from estore?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.