WordPress.org

Ready to get started?Download WordPress

Forums

Custom Category Confusion (5 posts)

  1. danhodkinson
    Member
    Posted 2 years ago #

    Hi all,

    I have a custom content type called Products which i have created a template for which lays out my products in a grid view.

    I have these products in different categories. I want the categories page to be exactly the same as my template page i have created but i can't seem to do it.

    The category page seems to use the page.php template, i have tried a few different codes but can only seem to get it to display all of the products (in ever category) or no products.

    if anybody could help me with the code that would just grab the right products then i can do the rest. i have tried a basic `<?php while ( have_posts() ) : the_post(); ?>' loop just trying to pull the title but that just stays empty??

    Any ideas?

    Thanks
    Dan

  2. KristinCodesWP
    Member
    Posted 2 years ago #

    You could query the category specifically by doing something like this:

    <?php $my_query = "cat=CATEGORYIDNUMBER&posts_per_page=-1"; $my_query = new WP_Query($my_query); ?>
    <?php if ($my_query->have_posts()) : while ($my_query->have_posts()) : $my_query->the_post(); ?>
    
    WHATEVER YOU WANT TO DO TO EACH ITEM IN THE CATEGORY
    
    <?php endwhile; // end of one post ?>
    <?php endif; //end of loop ?>
  3. danhodkinson
    Member
    Posted 2 years ago #

    The only trouble with that is I have about 20 different categories and so i wanted to avoid code that pointed to categories incase i add more and then i need to add more code.

    Dan

  4. danhodkinson
    Member
    Posted 2 years ago #

    still haven't figured this one out.

  5. danhodkinson
    Member
    Posted 2 years ago #

    I've just come back to this but still can't figure it out?
    Anybody have any suggestions?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.