DukaPress Category Pages

59

If you have used DukaPress for any length of time, it is probable that you have come across something really annoying: products do not show up on your categories. Additionally, if you want to create pages which show your products using the grid view, you currently have to go through the painful process of creating separate pages for each category, then inserting the gird view shortcode into each page. This is less than ideal. Explaining this process to a client becomes ‘difficult’.

What if each category could just automatically show your products in the gird view without the need of you doing anything other than just…. putting your products in their respective categories? With help from Cookie Web, we’ve figured out a way to do just this.

How do you do this?
Basically, you need to create a custom category template for your theme and make it such that when your categories are viewed, the grid display shortcode is used to generate a page that shows your products nicely.

Every theme’s category templates will be different in terms of HTML and CSS but to achieve what we are describing you just need two pieces of code:

A. This code gets the category ID of the category being viewed


B. This code then inserts the category ID into the grid display shortcode so that you can generate your product category pages:


C. Optionally, you can use this bit of code to print the category name somewhere on the page:

name ?>

See it in action
Our latest themes Mwendo, Sanaa, Begi and ShopKeeper already include this functionality. You can download them to see exactly how we implemented this. You can view their demos to see it in action – make sure you click on the categories!

59 Responses

  1. Mark says:

    Thank you for this!!

    I got the code to somewhat work except above the products it’s displaying

    “Not Found

    Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.”

    and a search box…. I’m unsure of how to get rid of that.

  2. Mark says:

    I figured it out!!! Thank you again

  3. Sebastian says:

    Hello there,

    I’m really noob programmer and i’d love to know where the heck to put that code 😛

    Sorry for being such an idiot and thanks for your help!

    • Kelvin says:

      Hey Sebastian!

      Most themes have either: archive.php, category.php, or index.php. You need to take one of these files (back up :P) and then look at the code, you will notice that generally there is a php “while” statement, followed by “if” and “else if”. These are where the theme is calling the loop to display the category contents.

      Somewhere, you will notice something like the_content or the_excerpt inside a php statement. This is where a post;c content is displayed. So delete the php there and put in all the code above instead.

      Then go through the rest of the file and delete all the other php while and if statements. make sure to leave all the “div” statements in tact.

      If you do this, then rename your file “category.php” and you’ll be done.

      I have generalised things because of the sheer number of themes and all their different approaches, but its the basic procedure.

  4. Sebastian says:

    Hey Kelvin!

    I tried following your good advice, but im not good enough and i brake down all the file ROFL!

    This is the archives.php in my theme; i tried deleting all the “if” and “else” below “while” but still can’t make it work 🙁

    Pastebin: http://pastebin.com/kyX3BcLb

  5. paul says:

    hello

    i am using the default wordpress twenty ten theme and looked through the index, archives and category files and found no “while” statement. i am just not getting where the 2 pieces of code go…….

    i would love to make this work. thanks

  6. paul says:

    So i logged in a gave you a 5 star rating and it made you have the “green works!” status. thanks, yeah, the website is a work in progress, but coming along.

  7. agung says:

    will you help me to changes the code , which i used http://demo.themesbell.com/fashionable/ for the themes, really i blind on coding…thx,,very2 simple shopping cart’..two thumbs Up

    • Kelvin says:

      I’d love to help – but you gotta make an effort too. Where have you installed DukaPress? I cannot see your products.

      • agung says:

        i installed in my web http://www.addnique.com cek it out,..?are you need to email archieve.php..?

        here is

        ID);
        //$num_comments = $num_comments->approved;

        $i++;
        ?>
        <div class=" post_box” id=”post-“>
        ID);
        $pattern= “/(?post_content;
        $searchimages = ‘~]* />~’;

        /*Run preg_match_all to grab all the images and save the results in $pics*/

        preg_match_all( $searchimages, $content, $pics );

        // Check to see if we have at least 1 image
        $iNumberOfPics = count($pics[0]);

        if ( $iNumberOfPics > 0 ) {
        // Your post have one or more images.
        $imgTagFirst = $pics[0][0];
        $pattern= “/(?

        <a href="” title=””><img src="/include/timthumb.php?src=&h=&w=&zc=1″ alt=”” title=”” />

        <div class="”>
        <div class="”>
        <h1 class="”><a href="” title=””>
        <p class="”>//  |  <a href="” class=”” title=””> <img src="/images/comment_icon.png” alt=”” title=”” />

        Sorry
        No posts found.

        <?php /*

        */ ?>

  8. Daniel K says:

    Hi All,
    Am I correct in assuming that I MUST use the shortcodes to display products?

    I tried to just loop through the post_type duka but that did not work 🙁

    Thanx,
    Daniel

    • Kelvin says:

      It is not correct to say that because at the end of the day the products and related info are just a custom post type (named ‘duka’) with custom fields (for price, weight, variations, etc). So you can definitely loop through the post type and display them but keep in mind to call the custom fields.

      The only thing that will be problematic with this method will be:
      1. displaying the “add to cart” button.
      2. displaying the images using the DukaPress image effects – you will just get attached images the normal WordPress way

      But I am certain that you can re-use the code in dp-products.php to do much more than our shortcodes do 🙂

      • Daniel K says:

        Thanx Kelvin, but it won’t work for me.

        Here is the query I set up:

        query_posts( ‘post_type=duka&posts_per_page=12&paged=’.$paged.” );

        and I get a page with the title Boutique and the author’s name. I am using the_content(); and am not getting the content. I have not tried to get the
        meta data.

        Am I missing something? I use custom post types all over the place so I figured this should wor. Any ideas?

        Thanx in advance,
        Daniel

  9. Daniel K says:

    HI All,
    I was just wondering if it was possible to set my Product Variations ( Sizes, Colors, etc ) as a Master Dropdown list. My client has multiple products that use the same set of sizes and it would make her life a lot easier if she did not have to enter each size every time she enters a new product.

    Is there a way to set these so all she has to do is select for example “T-Shirt sizes” or “Sleepwear Sizes” depending upon the product.

    Thanx,
    Daniel

  10. LD says:

    Hi,

    i’ve been searching what’s wrong with all the widgets positions when a category is clicked.
    those widgets top position is somehow pushed down as if the product grids are placed above them. in other word, the sidebar layout is messed when i clicked on the category name. ie. http://www.lamozeshop.com/category/import-collection/

    this is only happening when i clicked on categories. the widgets are placed properly when i open a specific product’s page, the searched results, an even on a page with product grids shortcode.

    can you help me, please?

    thanks in advance,
    LD

    • Kelvin says:

      Hey LD. How are you? Unfortunately we cannot do much to help you. The category page is loaded using your themes category template. The problem here is to be found in your category template inside your theme. It is probably something really tiny, too.

      • LD says:

        Hey Kelvin, thanks for your response. The problem is… the theme (http://wordpress.org/extend/themes/pretty-theme) does not have any category template. So by default, it cannot displays the grid at all.
        So I “borrowed” the category.php from shopkeeper theme, and it works fine, except on the category page. It seems that the sidebar is somehow placed after the category content (which is the grids).

        thank you,
        LD

        • Kelvin says:

          Hmm, not a good idea to do that. It would have been better & easier to use archive.php or even index.php

          All the same, I managed to make it okay for you using your theme’s archive.php. Enjoy:

          http://pastebin.com/CvsEAh88

          • LD says:

            Hi Kelvin,
            this afternoon, I managed to make fix it by adding class = “narrowcolumn” at the first div line. hahaha… inspired by the pretty theme original page.php file content. 😀
            want to post comment here but my connection got problem.

            once i can online, i tried your template based on pretty theme’s archive.php. but somehow it does not even shows the grid at my site. 🙁 so i undo it and switched back to my “fixed” version.
            here it is: http://pastebin.com/EMe5XJRf

            again… thank you for your help Kelvin.
            oh yeah… i think DP needs a forum to discuss problems and for more hacks to make it more and more compatible. 😀

            good luck for you and DukaPress!

            sincerely,
            LD

  11. Emily B. says:

    Hey, Kelvin,

    I am trying to do this to my FlexxCamo theme, but it just isn’t working. Maybe I am doing it wrong, could you explain how to do it for the FlexxCamo theme?

    Thanks

    • Kelvin says:

      Really hard to help you out with such little info, sorry. Could you possibly give us temporary admin access? (duka.at.dukapress.org)

  12. Michelle says:

    As far as I can tell, I’ve done everything correctly thus far. I’m getting the error “Warning: Division by zero in /home4/homemae0/public_html/wp-content/plugins/dukapress/php/dp-products.php on line 326” on my product page called “Candles.” I went in through my cPanel, opened this doc, and went to line 326. There’s no 0 in it at all.

    Thanks in advance for your help.

  13. Amber says:

    Hey there. I’m a bit new to all this (had the site since Jan). I havent messed too much with the site in a couple months, but when I came back to it, one of my pages was not displaying the products in grid form. This is weird to me because one of my other pages is displaying the grid just fine and everything has the proper short codes. It seems as if something is overriding the shortcode on that one page because it is displaying all my products as if they were all individual posts. Very weird. Anyway, if there is any advice you can give me, that would be great!

    BTW…none of this happened until I updated Dukapress. Thanks again!

  14. Amber says:

    Yes, the URL for the site NOT displaying the grid is :

    http://graffitifacecosmetics.com/products/

    It displays it to where it looks more like individual blog posts.

    The URL for the sire actually displaying the grid properly is:

    http://graffitifacecosmetics.com/awareness-products/

    Thanks in advance!

  15. Amber says:

    Hey there. I tried to change it over and all it said was “Error”. Im just going to have to do away with Dukapress. I hate that I have to, but me and Duka have never gotten along. Thanks anyways!

  16. Amber says:

    I tried that and it did not work, but I will tell you what did…for SOME odd reason…the category ID number changed in the Dukapress Shortcode..so for anyone having this problem..make sure your category ID number is correct. Ever since I updated Dukapress, the category ID number changed. Thanks for all your help!

    -Amber

  17. donnie says:

    Keep up the great work of providing us with useful information.

  18. Justin Thurn says:

    Hi there!

    First I want to thank you for such a great plugin. I was hesitant at first, and chose Dukapress solely because I can use integrated Alertpay, but now I’m glad I have it for other reasons as well.

    I am having a heck of a time getting this to work. I have tried several different variations, but none of them function 100%. The link below is the version that has worked the best so far, as well as the original file. The link in my name will take you right to an example page on my site in progress.

    http://pastebin.com/8Pi8SWWa

    Thanks again for a great product. I have several of the premium modules, and they certainly streamline a lot of things for me. What I notice most about Dukapress is the level of support. I have never seen anyone give such direct, hands-on support.

    • Kelvin says:

      Thanks Justin. Sorry it took long to get back to you. Please use the forums for faster response next time 🙂

      If you can send this theme to duka(at)dukapress.org, we’ll sort it out and send it back 🙂

      Thank you for your kind words, VERY much appreciated.

  19. jack starks says:

    Hello
    Plug in your WordPress plugins I use and it is great
    I do not know where this program should be written to accommodate
    If you are on the tags and how they can help
    Persian-speaking friend, I am
    Thank you

Leave a Reply

© 2024 DukaPress. All rights reserved.
Design By Madoido.