- This topic has 28 replies, 5 voices, and was last updated 3 years, 2 months ago by
Fernando.
-
AuthorPosts
-
February 21, 2023 at 12:49 am #2540797
jmarc
Hello
about this code wich work fine, I would like to add, lets’ say another adds after 9th post (I keep 5th also).
What piece of code should I add please ?
Thank you
MArcFebruary 21, 2023 at 12:56 am #2540809Fernando Customer Support
Hi Jmarc,
Would the ad code be the same after the 5th and 9th posts?
February 21, 2023 at 1:10 am #2540824jmarc
I don’t understand Fernando …
Let’s say an add 1 after the 5th post and an add2 after the 9th…February 21, 2023 at 1:33 am #2540844Fernando Customer Support
Can you try this code:
add_shortcode('portable_hook', function($atts){ ob_start(); $atts = shortcode_atts( array( 'hook_name' => 'no foo' ), $atts, 'portable_hook' ); do_action($atts['hook_name']); return ob_get_clean(); }); add_action('generate_after_do_template_part',function(){ global $loop_counter; $loop_counter++; if ( $loop_counter == 5 ) { echo do_shortcode('[portable_hook hook_name="after_fifth_post"]'); } else if ( $loop_counter == 9 ) { echo do_shortcode('[portable_hook hook_name="after_ninth_post"]'); } });With this, you’ll have these two hooks:
after_fifth_postafter_ninth_postFebruary 21, 2023 at 1:41 am #2540848jmarc
Thank you Fr=ernando but It doesn’t work 🙁
February 21, 2023 at 1:55 am #2540868Fernando Customer Support
I edited and tested the code above. Can you try that instead?
February 21, 2023 at 2:00 am #2540872jmarc
Thank you Fernando
How can I put this in the element please ? I’m lastFebruary 21, 2023 at 2:04 am #2540874Fernando Customer Support
1. Go to Appearance > Elements and create a new Hook Element.
2. Set the Hook to Custom and in the field provided add:after_fifth_post
3. Add your Advertisement code.
4. Set the Display rule location.
5. Repeat steps 1 to 4 forafter_ninth_postFebruary 21, 2023 at 2:21 am #2540897jmarc
Thank you but only the 5th one is online , the other no 🙁
I’m retrying…February 21, 2023 at 2:50 am #2540925Fernando Customer Support
Both are working and showing when I tested the code.
Can you make sure you created two Hook Elements using the two Hooks I provided?
February 21, 2023 at 3:03 am #2540947jmarc
Yes I did Fernando … don’t know why It doesn’t work …
Still looking at ItFebruary 21, 2023 at 3:11 am #2540957jmarc
I guess It’s maybe I Use infinite scroll …
After testing I’ts not that neither…February 21, 2023 at 6:10 am #2541143jmarc
It’s ok … i had to add more articles in a page …
Thank’s a lot Fernando !February 21, 2023 at 6:02 pm #2541939Fernando Customer Support
You’re welcome, Jmarc!
-
AuthorPosts
- You must be logged in to reply to this topic.