- This topic has 7 replies, 3 voices, and was last updated 7 years, 5 months ago by Tom.
-
AuthorPosts
-
November 25, 2016 at 1:24 am #247486Lyle
Hi Tom,
Thought that I would ask here if that’s OK.
Further to this post from the GP Addon forum:
https://generatepress.com/forums/topic/hook-question/
You posted this as a PHP solution for an array of pages to exclude:
<?php if ( ! is_page( array( 'my-excluded-page-slug', 'another-page', 'one-more' ) ) ) : ?> <?php echo do_shortcode( '[your-shortcode]' ); ?> <?php endif; ?>
This works great with the GP Hooks π However, how would one adjust this code to also exclude a post category named Blog? I tried a few things, even from Stack Overflow, but all I got were errors on those post pages π
Any assistance will be greatly appreciated and I promise to get some GP and GP Premium tutorials up ASAP π
Cheers!
LyleNovember 25, 2016 at 9:58 am #247676TomLead DeveloperLead DeveloperConditionals can get pretty complex when you start having multiple parameters.
You could try this:
<?php if ( ( ! is_page( array( 'my-excluded-page-slug', 'another-page', 'one-more' ) ) ) || ! is_category( 'blog' ) ) : ?> <?php echo do_shortcode( '[your-shortcode]' ); ?> <?php endif; ?>
November 25, 2016 at 4:36 pm #247823LyleHmm, once I updated with that code (using my values for pages and the blog category (as that is what it is named), the shortcode now displays everywhere π
I may just end up doing this scenario manually π
Basically, what I am trying to achieve is have a notice (created with Elementor and using the AnyWhere ELementor plugin shortcode to display it) displayed on all of the SV tutorial pages only and nowhere else. That is why I was thinking, OK, use the !page and list all the main menu items and then the !category so as not to appear on the posts in that category.
I could manually add that shortcode to each of those tutorial pages, but the hook method would make it “auto-magic” for all new tutorial pages … just me being lazy π
November 25, 2016 at 5:27 pm #247840JamalHi Lyle
Maybe its easier to target a specific category/ page than excluding everything else except that category/page?
You could put all the tutorials in a tutorial category and target that tutorial page/ and category?
November 25, 2016 at 5:43 pm #247847LyleHi Jamal,
Yes, that would probably work better but unfortunately all the tutorials are pages, not posts.
November 25, 2016 at 6:27 pm #247855JamalLooking at your site i see /tutorials/tutorial-name, are you using Tom’s wpsp plugin? maybe its possible to target wpsp_id?
Sorry if that doesnt help either.
November 25, 2016 at 6:31 pm #247856LyleOnly using WPSP for the Tutorials page, the individual tutorial pages are just pages.
But it’s a moot point now … for the time being anyway … as I have just finished manually adding the shortcode to each of the required pages π
I’ll maybe revisit this later, but for now, I’ll mark it Resolved.
November 25, 2016 at 8:47 pm #247876TomLead DeveloperLead DeveloperIf you need more help with that conditional in the future just let me know π
-
AuthorPosts
- You must be logged in to reply to this topic.