0
<?php get_header(); ?>
<div id="section1-inner">
    <div class="container">
        <div class="row">
            <div class="col-lg-3 col-md-3 col-sm-12 col-xs-12">
                <div class="left-sec1">
                    <img src="<?php bloginfo('template_directory'); ?>/images/logo.jpg"  alt=""></div>
                    <div class="left-sec2"><h2>Category</h2></div>
                    <div class="left-sec3">
                        <ul><?php if ( !dynamic_sidebar('Product Category') ) ?></ul>
                    </div>
                    <div class="left-sec4">
                        <ul><?php if ( !dynamic_sidebar('Homepage Banner') ) ?></ul>
                    </div>
                </div>
                <div class="col-lg-9 col-md-9 col-sm-12 col-xs-12">
                    <div class="form-gap"><?php get_search_form(); ?></div>
                    <div class="gallery"><?php wd_slider(1); ?></div>
                    <div class="clearfix"></div>
                    <h3 class="title"><?php printf( __( '%s', '' ), '<span>' . single_cat_title( '', false ) . '</span>' ); ?></h3>
                    <?php
                    $query = new WP_Query( array( 'post_type' => 'product', 'orderby' => 'menu_order', 'order' => 'ASC', 'showposts' => 5) );
                    while ( $query->have_posts() ) {
                        $query->the_post();?>
                        <?php wp_reset_postdata(); } ?>
                        <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
                            <div class="pbox">
                                <center><?php the_post_thumbnail(); ?></center>
                                <h3><a href="<?php the_permalink(); ?>"><?php the_title( ); ?></a><br></h3>
                                <h4><?php the_field('offer_price', $taxonomy); ?></h4>
                                <h5><?php the_field('price', $taxonomy); ?></h5>
                                <p class="text-center"><a href="<?php the_permalink(); ?>"><img src="<?php bloginfo('template_directory'); ?>/images/download.png" alt=""></a></p>
                            </div>
                        </div>
                </div>
            </div>
        </div>
    </div>
    <?php get_footer(); ?>

Here is my wordpress category page coding.

When I was putting this code into category.php page, it is only showing 1 category posting under the post_type of "Product" .

As for example, I already created 3 category: Category 1, Category 2, Category 3 and each category have 3 post. So as per my above code, it is showing only 1 post.

But I want to show all posting under each category posting.

can anyone help me?

0

You're calling wp_reset_postdata() and closing the loop before displaying the content of the posts.

The WordPress Codex has a good example of how to build a custom query:

<?php
// example args
$args = array( 'posts_per_page' => 3 );

// the query
$the_query = new WP_Query( $args );
?>

<?php if ( $the_query->have_posts() ) : ?>

    <!-- start of the loop -->
    <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
        <?php the_title(); ?>
        <?php the_excerpt(); ?>
    <?php endwhile; ?><!-- end of the loop -->

    <!-- put pagination functions here -->
    <?php wp_reset_postdata(); ?>

<?php else:  ?>

<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>

<?php endif; ?>

I've fixed the code for you here and added some comments:

<?php get_header(); ?>
<div id="section1-inner">
    <div class="container">
        <div class="row">
            <div class="col-lg-3 col-md-3 col-sm-12 col-xs-12">
                <div class="left-sec1">
                    <img src="<?php bloginfo('template_directory'); ?>/images/logo.jpg"  alt="">
                </div>
                <div class="left-sec2"><h2>Category</h2></div>
                <div class="left-sec3">
                    <ul><?php if ( !dynamic_sidebar('Product Category') ) ?></ul>
                </div>
                <div class="left-sec4">
                    <ul><?php if ( !dynamic_sidebar('Homepage Banner') ) ?></ul>
                </div>
            </div>
            <div class="col-lg-9 col-md-9 col-sm-12 col-xs-12">
                <div class="form-gap"><?php get_search_form(); ?></div>
                <div class="gallery"><?php wd_slider(1); ?></div>
                <div class="clearfix"></div>
                <h3 class="title"><?php printf( __( '%s', '' ), '<span>' . single_cat_title( '', false ) . '</span>' ); ?></h3>
                <?php
                $query = new WP_Query( array( 'post_type' => 'product', 'orderby' => 'menu_order', 'order' => 'ASC', 'showposts' => 5) );
                if ($query->have_posts()) : // Always check if there are any results before looping
                    while ( $query->have_posts() ) {
                        $query->the_post(); ?>
                        <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
                            <div class="pbox">
                                <center><?php the_post_thumbnail(); ?></center>
                                <h3><a href="<?php the_permalink(); ?>"><?php the_title( ); ?></a><br></h3>
                                <h4><?php the_field('offer_price', $taxonomy); ?></h4>
                                <h5><?php the_field('price', $taxonomy); ?></h5>
                                <p class="text-center"><a href="<?php the_permalink(); ?>"><img src="<?php bloginfo('template_directory'); ?>/images/download.png" alt=""></a></p>
                            </div>
                        </div>
                    <?php }
                    wp_reset_postdata(); // Called after the while loop for the query finishes
                endif; ?>
            </div>
        </div>
    </div>
</div>
<?php get_footer(); ?>

Edit: After reading your comments, it seems like what you want to achieve is showing only the posts for the current category. You've taken a different approach to this by setting up your own WP Query, so you'll need to add another argument to get the posts for the currently queried category, using $wp_query->get_queried_object_id().

Replace your $query = ...-line with the following:

$query = new WP_Query( array( 'post_type' => 'product', 'orderby' => 'menu_order', 'order' => 'ASC', 'showposts' => 5, 'cat' => $wp_query->get_queried_object_id()) );
  • It is not working Emil. As it is showing all posing from all category. As per your coding, I have used tis into my category.php page. But it is not showing perfect category posting. When I click on Category1, it is showing all posting from Category 1, Category 2, Category 3 . So please tell me perfect coding. – user108499 Dec 7 '16 at 11:56
  • Can you try to explain what you are trying to do? I don't understand. – Emil Dec 7 '16 at 14:03
  • As per your suggested coding, I have used this for my category.php page. here is the live example: infoproductexpert.com/category/category-1 . Here all posting are showing, instead of specific category product. can you send me modified code again. – user108499 Dec 8 '16 at 11:04
  • See my updated answer. – Emil Dec 8 '16 at 11:30
  • Thanks for your solution. I'm very happy. You are really great. – user108499 Dec 8 '16 at 12:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy