conditional php
This topic contains 8 replies, has 3 voices, and was last updated by Scott Harris 6 years, 5 months ago.
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket-
AuthorPosts
-
July 22, 2019 at 5:50 pm #498947
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.
July 23, 2019 at 12:50 am #498991Only 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.July 23, 2019 at 6:23 pm #499188We’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/July 23, 2019 at 11:13 pm #499277We have examples here: https://wpgeodirectory.com/docs-v2/faq/common-examples/#logic
July 23, 2019 at 11:45 pm #499285Thanks, 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’ )
July 23, 2019 at 11:50 pm #499286You are using that in widget logic?
Please share WP Admin credentials and you URL in a private reply so we can take a lookJuly 24, 2019 at 12:40 am #499295This reply has been marked as private.July 24, 2019 at 10:28 am #499330Hi @scottclientclicks-com,
Instead of in_category() please try it.is_tax( 'gd_placecategory', 'sonoma-wineries' )Let me know if any issue?
Thanks
July 24, 2019 at 2:44 pm #499380Thank 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.
-
AuthorPosts
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket