Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6684881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:59:28+00:00 2026-05-26T04:59:28+00:00

In the below code there’s a loop that features all products under a given

  • 0

In the below code there’s a loop that features all products under a given category:

        <?php        

            wp_reset_query();
            query_posts($query_string . '&posts_per_page=15&paged=' . $paged);
            if (have_posts()) :
            while ( have_posts() ) : the_post();
                $price =  get_post_meta(get_the_ID(), 'inception_price', true);

        ?>

            <div class="omc-product-listing">
                <a href="<?php the_permalink();?>">
                    <?php 

                        if(has_post_thumbnail()) {
                        the_post_thumbnail('product', array('class' => 'omc-product-frame'));  
                        } else {
                    ?>

                    <img src="<?php echo get_template_directory_uri() ;?>/images/no-image.png" width="170" height="170" class="omc-product-frame" alt="no photo" />

                    <?php } ?>

                </a>

                <span class="omc-listing-header"><a href="<?php the_permalink();?>"><?php the_title();?></a></span>

                <span class="omc-listing-price"><?php echo($price);?></span>

                <span class="omc-listing-more"><a href="<?php the_permalink();?>">&raquo;</a></span>

            </div><!-- /omc-product-listing -->

        <?php endwhile;  ?>

        <br class="clear" /> 

        <div class="product-pagination">

            <?php  kriesi_pagination(); ?>    

        </div>                        

        <br class="clear" /> 

        <?php endif; wp_reset_query(); ?>

In this loop, I’d like to pull out every product for a given category (that’s what the code does now), but display then “per subcategory”, like this:

For category publications:

Books:

  • Book 33
  • Book 32
  • Book 1
  • …

Mobile Apps:

  • App 12
  • App 76
  • …

…

I think the code above needs a foreach loop, like below, but I don’t know how to implement it in this case.

            <?php
            // get all the categories from the database
            $cats = get_categories();

                // loop through the categories
                foreach ($cats as $cat) {
                    // setup the categories ID
                    $cat_id= $cat->term_id;
                    // Make a header for the categories
                    echo "<h2>".$cat->name."</h2>";
                    // create a custom wordpress query
                    query_posts("cat=$cat_id&post_per_page=100");
                    // start the wordpress loop!
                    if (have_posts()) : while (have_posts()) : the_post(); ?>

                        <?php // create our link now that the post is setup ?>
                        <a href="<?php the_permalink();?>"><?php the_title(); ?></a>
                        <?php echo '<hr/>'; ?>

                    <?php endwhile; endif; // done our wordpress loop. Will start again for each category ?>
                <?php } // done the foreach statement ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:59:29+00:00Added an answer on May 26, 2026 at 4:59 am

    I’ve taken this request to wpquestions.com. It just got resolved by Abdessamad Idrissi. the answer is too long to copy it here, so I’m posting the discussion link and the code link here, in case someone has the same need.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the code below is there a nicer way to right it that doesn't
For the below code, there ia a form in the location /home/form.php .How can
Getting Undefined index: filename error in the below image upload php code. Is there
I would like to hear opinions on below code snippet. Is there anything that
The below code works when there are a few element in the To list
I have below code to insert a style into DOM (there is a use
Normally I use the below code, but is there a better way? lastOfMonth =
When running the below code a type is never returned, despite there being a
In the below code instead of specifying the tab name.. Is there anyway we
The code below is resulting in an error on a site in which there

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.