• Resolved tommyqr

    (@tommyqr)


    Wow! This plugin is amazing. I have come a long way since first trying it two weeks ago. I really like it.

    I tried to find something in the forum and also looked in the documentation and tried a few things, but can not seem to find a solution.

    I want to display the message ‘No products for this subcategory (child)’ when there are no products for a specific child category.

    I tried the following code but it did not work. I am not sure what to do. Any help would be much appreciated.

    ‘[for each=”product_cat” parents=”true” term=”brands”]
    [if children]
    [-for each=”child”]
    <font color=”214B63″><b>[-each]</b></font> [loop type=”product” columns=”1″ orderby=title] <b>[field title]</b> [field thumbnail-link] [/loop] [/-for]
    [else]
    No products
    [/if] [/for]’

    Thank you.

    https://www.ads-software.com/plugins/custom-content-shortcode/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Eliot Akira

    (@miyarakira)

    Hello,

    I think this can be achieved with the [for-else] shortcode. If you want to display something when there is no post under a child category:

    [-for each=child]
      ..the loop for posts in child category..
    [-for-else]
      No products in this child category.
    [/-for]
    Thread Starter tommyqr

    (@tommyqr)

    Thank you for replying.

    I tried your code. Here is what I have.
    ‘[for each=”product_cat” parents=”true” term=”brand”]
    [each]
    [-for each=child]
    [each]
    [-for-else]
    No products to display
    [/-for]
    [/for]’

    I need to go one more level deeper.

    I probably did not explain what I am trying to do well enough. Sorry for that.

    I have several parents (brand, type, etc)
    I have several children of each parent For the parent Brand I have Kenneth Cole, Ralph Loren, Kate Spade, etc.
    I have several children of each child. (Kenneth Cole shirt xxx, Kenneth Cole Shiny Shoe xx, etc)

    I am looking to check for no products for each brand name. (I want to say ‘No products (for Kate Spade) if I do not have any yet.

    I tried some other code to get the ‘no product’ message at the child of the child, but have not been able to get 3 levels deep yet.

    Is Custom Content Shortcode designed to handle three levels deep? (Brand, Brand Name, Product of Specific Brand). If so what do you suggest I try?

    Thanks for your kind help

    Plugin Author Eliot Akira

    (@miyarakira)

    The [for] loop can go 3 levels deep, but there may be an easier way..

    Would something like this work?

    [for each=product_cat parent=brand]
      [if children]
        Brand: [each]
        [-for each=children]
          Product: [each]
        [/-for]
      [else]
        No products for [each]
      [/if]
    [/for]
    Thread Starter tommyqr

    (@tommyqr)

    I know there is a solution. I tried the code above, but I did not get any children to display.

    I tried several ways of coding, but have not come up with a solution y6t. Changing the location of the loop, if children and if. So far nothing I tried works. I want this to work because I believe Custom Content Shortcdes offers limitless opportunities. I have tried over ten other plugins but each has its limitations. I truly believe this plugin is very amazing.

    The following code displays the products of the brand, but it also displays the message (no products) for all brands even when they have products. I have tried several hours to find a solution, but it is time to find out what I do not understand about the plugin.

    Here is my latest code which at least displays products when they exist. I just do not know why the ‘no product’ message displays even when products exist and display.

    ‘[for each=product_cat term=brand]
    [each]
    [-for each=child]
    brand: [each]
    [loop type=”product”] <u>[field title-link]</u> [field thumbnail-link] [field image-description] [/loop]
    [if children]
    Product : [each]
    [loop <u>[field title-link]</u> [field thumbnail-link] [/loop]
    [else]
    No products for [each]
    [/if]
    [/-for]
    [/for]

    ‘[for each=product_cat term=horse-power]
    [each]
    [-for each=child]
    brand: [each]
    [loop type=”product”] <u>[field title-link]</u> [field thumbnail-link] [field image-description] [/loop]
    [if children]
    Product : [each]
    [loop <u>[field title-link]</u> [field thumbnail-link] [/loop]
    [else]
    No products for [each]
    [/if]
    [/-for]
    [/for]’

    Thank you for any ideas.

    Plugin Author Eliot Akira

    (@miyarakira)

    Whew! I think the problematic part is this:

    [if children]
    Product : [each]
    [loop <u>[field title-link]</u> [field thumbnail-link] [/loop]
    [else]
    No products for [each]
    [/if]

    The loop looks broken but that’s probably just a copy & paste error.

    So..if there are child terms..you probably want to loop through them using [for] also?

    [if children]
    [--for each=child]
    Product : [each]
    [loop type=product]<u>[field title-link]</u> [field thumbnail-link] [/loop]
    [/--for]
    [else]
    No products for [each]
    [/if]

    Hmm, but you said this:

    but it also displays the message (no products) for all brands even when they have products

    So maybe [if children] is not working correctly in a nested [for] loop. I’ll set up a test for this and see what I find out.

    Another thought.. Maybe what you want is not [if children] – which checks the existence of child terms – but something else to check existence of posts with the current term in the [for] loop? In that case, instead of using [if children] you can do something like..

    [loop type=product]
    [if first]Product: [each][/if]
    <u>[field title-link]</u> [field thumbnail-link] [field image-description]
    [if empty]No products in [each][/if]
    [/loop]
    Thread Starter tommyqr

    (@tommyqr)

    Wow! Custom Content Shortcode plugin does work!! Hurray!!
    Thank you for your suggestions above. You are correct [if children] was not working correctly in a nested [for] loop. However your last suggestion WORKS. Hurray.

    Here is the code that work to display products by brand within the parent (brand) and to display ‘no products found’ if none exist for a specific child brand.

    ‘[for each=product_cat term=brand]
    [each]
    [-for each=child]
    [loop type=”product”]
    [if first] product: [each] [/if]
    <u>[field title-link]</u> [field thumbnail-link] [field image-description]
    [if empty][each]
    No products found[/if]
    [/loop]
    [/-for]
    [/for]’

    Thank you very much for helping me understand more about how to use the plugin.

    Plugin Author Eliot Akira

    (@miyarakira)

    Great, I’m glad we found a solution.

    Looking at the last code, it feels like it could be made simpler. The first [for] loop is only getting 1 specific term, so maybe it could be combined with the second one to get child terms like this:

    Brand
    [for each=product_cat parent=brand]
    [loop type=product]
      ...
    [/loop]
    [/for]
    Thread Starter tommyqr

    (@tommyqr)

    Thanks for your code idea above. As you suggested, it works great and it definitely eliminates one [for each].

    Great Idea. Thank you.

    I added some style to it and display the products in 3 columns.
    ‘<h2 style=”text-align:center; color: #ffffff; background-color: #005ce6;”> BRAND </h2>
    [for each=product_cat parent=brand]
    [loop type=product columns=”3″ pad=”0px 10px”]
    [if first] <font color=”blue” Font-size=”18px”><b>[each]</b></font>[/if]
    <b><u>[field title-link]</u></b> [field thumbnail-link] <font color=”black” font-weight=”normal”> [field image-description]</font>[field image-caption]
    [if empty] <font color=”blue” Font-size=”18px”><b> [each] </b> </font>
    <font color=”#45756″> Products Coming Soon </font>[/if]
    [/loop]
    [/for]’

    I noticed that the documentation was updated. Great. Now that I have had some experience with this great plugin I need to reread the documentation and see what other great things it can do.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Need to display 'no products found for subcategory (child) of Parent’ is closed to new replies.