Community Forums › Forums › Archived Forums › Design Tips and Tricks › Two conditional tags in one hook
Tagged: conditional tags, shortcodes, Simple Hooks
- This topic has 4 replies, 2 voices, and was last updated 8 years, 3 months ago by
Victor Font.
-
AuthorPosts
-
August 13, 2015 at 1:29 pm #162281
msongbird
ParticipantI am using Genesis Simple hooks to add conditional tags.
I want to use one hook to display a slider on the homepage only and in that same position (hence same hook) to display a table on category pages.
After googling for hours and going way back into these forum archives. I came up with this code:<?php }
if ( is_single() ) { ?>
<div id="meteor-slideshow-wrap">
[meteor_slideshow slideshow="homepage-slider"]
</div>
<?php }elseif ( is_category(6) ) { ?>
[table id=1 /]
<?php }But it doesn't work. I just can't seem to figure out how to add two conditional tags into the same hook area.
Help appreciated.
http://www.songbirdblog.com/decorating-gallery
MarianneAugust 13, 2015 at 1:59 pm #162286Victor Font
ModeratorYou're logic isn't correct. Is_single is true for any post regardless of category. In your logic, is_single executes first. Since it is true for every post, you will never get to test for the category. So the way your if statement reads logically is, "if this is a post, execute the home page slider and if it's not a post display the table if the category is 6." You're not testing for the home page and you're testing non-posts for a category. Neither condition will ever provide the result you want.
What you want to do is this:
<?php } if ( is_home () || is_front_page() ) { ?> <div id=”meteor-slideshow-wrap”> [meteor_slideshow slideshow=”homepage-slider”] </div> <?php } elseif ( is_single() && is_category( '6' ) ) { ?> [table id=1 /] <?php }
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?August 13, 2015 at 2:07 pm #162290Victor Font
ModeratorActually, the code I gave you is wrong. In your OP, you said you want the table to display on category pages. If that's true, this is the correct code:
<?php } if ( is_home () || is_front_page() ) { ?> <div id=”meteor-slideshow-wrap”> [meteor_slideshow slideshow=”homepage-slider”] </div> <?php } elseif ( is_category( ) ) { ?> [table id=1 /] <?php }
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?August 13, 2015 at 2:26 pm #162296msongbird
ParticipantHi Victor,
Thanks for wanting to help.
The single conditional tag was actually a typo, and should indeed have been is_home.Alas your code does not work. In fact it doesn't even render the slideshow on the homepage.
I have gotten so far as rendering the slideshow on the homepage as wanted.
When adding my second conditional tag in that hook I have been able to render the table BUT alas it showed up in the same div as the slideshow on the home page.Apart from not knowing how to combine the codes it seems as if a more pressing problem is that my shortcode won't work on category pages at all.
I have tried replicating the exact code I successfully use in that hook for the homepage and just change the conditional tag to the category page, with no resultsSeems as if even used in the hooks section with "execute short code on this hook" I can't make a shortcode render on a category page.
August 13, 2015 at 5:31 pm #162322Victor Font
ModeratorWhen I have to do things like this, I use the Genesis simple hooks plugin. It makes the work and code execution much easier.
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet? -
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.