conditional php

This topic contains 8 replies, has 3 voices, and was last updated by  Scott Harris 5 years, 2 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #498947

    Scott Harris
    Lifetime Member
    Post count: 74

    I like the flexibility of the v2 template design for archive pages. However, I wish I could add html blocks both above and below the listings loop for each category. Currently, I believe that we can only add html either above or below the loop for each category.

    As a workaround, I had an idea that I could create text blocks for each category as divi library modules. These library modules can be called in a template as shortcodes. So I should be able to echo shortcodes that display Divi text blocks using conditional php based on the GD category name or slug.

    Can you please give me a clue where I’m going wrong. I’m using a php widget to do it. It works fine when I call the divi section shortcode without a condition, just not with the conditional statement. I’m trying to call the slug of each category page.

    
    <?php
    if ( is_category( 'napa-valley' )) {
    echo do_shortcode('[showmodule id="220026"]');
    
    else if ( is_category( 'sonoma-county' )) {
    echo do_shortcode('[showmodule id="220049"]');
    ?>
    

    The code is getting called in the GD Archive template.

    #498991

    Alex Rollin
    Moderator
    Post count: 27815

    Only one category is present at one time.
    We usually recommend the use of widget logic, which uses WP conditional tags.
    https://codex.wordpress.org/Conditional_Tags
    Try that and let us know if it works for you.

    #499188

    Scott Harris
    Lifetime Member
    Post count: 74

    We’ve tried widget logic as well, but when we add the category slug, it’s not working.

    For instance, if I use widget logic to add this conditional tag to a widget, it’s not displaying on the sonoma-wineries archive page.

    is_post_type_archive(‘gd_place’) && is_category( ‘sonoma-wineries’ )

    The widget does display in the archive if I don’t use any tag or if I just use is_post_type_archive(‘gd_place’).

    Is our syntax wrong for the category logic? I’ve also tried in_category as shown in the the GDv2 documentation, but I think that in_category is used for displaying on individual posts with that category and not on the archive page.

    This is the page where it should display:
    http://wordpress-197435-914241.cloudwaysapps.com/winery/category/sonoma-wineries/

    #499277

    Alex Rollin
    Moderator
    Post count: 27815
    #499285

    Scott Harris
    Lifetime Member
    Post count: 74

    Thanks, but I did look over that resource page carefully before posting here. The problem is that the example on that page for filtering by category doesn’t seem to work.

    is_post_type_archive(‘gd_place’) && in_category( ‘some-category-slug’ )

    #499286

    Alex Rollin
    Moderator
    Post count: 27815

    You are using that in widget logic?
    Please share WP Admin credentials and you URL in a private reply so we can take a look

    #499295

    Scott Harris
    Lifetime Member
    Post count: 74
    This reply has been marked as private.
    #499330

    Naveen Giri
    Moderator
    Post count: 1559

    Hi @scottclientclicks-com,
    Instead of in_category() please try it.

    
    is_tax( 'gd_placecategory', 'sonoma-wineries' )
    

    Let me know if any issue?

    Thanks

    #499380

    Scott Harris
    Lifetime Member
    Post count: 74

    Thank you. That works great!

    I’m happy to say that I can now add html blocks both above and below the listings on each category page.

Viewing 9 posts - 1 through 9 (of 9 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
20% Discount Offer
Hurry! Get your 20% discount before it expires. Get 20% Discount