- This topic has 23 replies, 3 voices, and was last updated 3 years, 11 months ago by Tom.
-
AuthorPosts
-
April 26, 2020 at 9:13 pm #1257130GeneratePressUser
Hello,
Can you pls provide dummy conditional statement for:
If post id = XX show {Following shortcode or html or anything which we want}
Same pls provide for pages, post title, post slug etc if possible pls provide whole list of it, so that we can figure it out and create our code.
Thanks!
April 26, 2020 at 9:47 pm #1257151GeneratePressUserHello,
Ok I figured it out.
<?php if ( is_single( ‘post-id’ ) ) : ?>
Custom code here
<?php endif; ?>Here is the list of all WP conditional tags:
https://developer.wordpress.org/themes/references/list-of-conditional-tags/
April 27, 2020 at 4:09 am #1257502DavidStaffCustomer SupportGlad to hear you found your solution
May 2, 2020 at 2:26 pm #1266752GeneratePressUserHello David,
Now I got a new problem:
On using:
<?php if ( is_single( ‘post-id’ ) ) : ?>
[Custom shortcode here]
<?php endif; ?>It works cool
So we have 1 category with 35 posts so we have in created in elements > generate press hook, where we have such 35 codes at a place:
<?php if ( is_single( ‘post-id’ ) ) : ?>
[Custom shortcode here]
<?php endif; ?>Like that 35 times total, 1 for each post.
So it works fast and all is good, but when we add in each code more shortcodes like:
<?php if ( is_single( ‘post-id’ ) ) : ?>
[Custom shortcode 1]
[Custom shortcode 2]
<?php endif; ?>The page load time becomes 20 – 30 secs.
Can you pls give us a better way to integrate it? like maybe so many php open and close causing issues?
Also I tried implementing it like:
<?php if ( is_single( ‘post-id-1’ ) ) : ?>
[Custom shortcode 1]
<?php endif; ?><?php if ( is_single( ‘post-id-1’ ) ) : ?>
[Custom shortcode 2]
<?php endif; ?>So in short for 35 posts with each having 2 shortcode it makes it 35 x 2 = 70 such codes but I feel that works perfect and fast.
So, not sure why using 2 shortcodes inside together don’t work.
Is there a better way to implement which would reduce code size and help us keep same page speed?
Let me know.
Thanks!
May 3, 2020 at 2:47 am #1267129DavidStaffCustomer SupportWhy not just use the GP Hook element to add your Shortcodes ?
https://docs.generatepress.com/article/hooks-element-overview/You can set the Display Rules to Post Category to cover all of those posts.
May 3, 2020 at 6:55 am #1267373GeneratePressUserHello David,
That will be too many elements created there.
We have 200+ codes for 200+ posts.
So, making 200+ elements won’t be something good to manage, conditional is best, to manage and edit from the same place.
So it’s like 200 posts divided in 5 post categories, so just 5 elements with display rule of just post category in each and that each category having their post conditional elements.
Also pls we request u guys to add duplicate button for elements.
So, pls let me know better way to add that code.
Let me know 🙂
May 3, 2020 at 7:31 am #1267398DavidStaffCustomer SupportHow may DIFFERENT shortcodes do you have ?
May 3, 2020 at 7:38 am #1267406GeneratePressUserHello,
I have 3 – 4 shortcodes approx for each post so each post category on average have 20 – 50 posts and as told earlier each category has its element hook.
So, how to implement via PHP conditions to not ruin up speed.
May 3, 2020 at 7:49 am #1267559DavidStaffCustomer SupportSo for each post you have 3 – 4 different shortcodes ? So for 20 posts that could 60 different shortcodes ? Is that correct.
May 4, 2020 at 10:53 am #1269312GeneratePressUserHello David,
Yes it could increase that’s just estimate so 3 – 4 for each post and have such 215 approx posts
But can you tell why you are counting that? I just need PHP implementation better way or some different code.
So, let me know 🙂
May 4, 2020 at 4:42 pm #1269693TomLead DeveloperLead DeveloperHi there,
[Custom shortcode 1]
[Custom shortcode 2]
The page load time becomes 20 – 30 secs.
So having two shortcodes in the conditional increased the load time like that? Do the shortcodes execute once the page does load?
May 4, 2020 at 7:57 pm #1269805GeneratePressUserHello,
Yes or else speed is 1 – 2 sec max.
And weird thing is if written just 1 short code in condition then it works fast.
So I tried writing both shortcodes seprate (not in same php condition) and it works fast.
But this makes all conditions = number of shortcodes, in short making code double.
Is there a better way to implement it?
May 5, 2020 at 4:50 am #1270273DavidStaffCustomer SupportI think if we had a better understanding of what the shortcodes do and their relationship to each post then we may be able to provide a better alternative.
What i am trying to understand is how many actual unique shortcodes do you have ?
Is it 200 posts x 4 different shortcodes = 800 shortcodes ?
Or is is just 4 different shortcodes ?May 5, 2020 at 5:53 am #1270370GeneratePressUserHello,
It’s different shortcodes, not same.
May 5, 2020 at 5:55 am #1270371DavidStaffCustomer SupportSo potentially around 800 different shortcodes ?
-
AuthorPosts
- You must be logged in to reply to this topic.