Site logo

[Resolved] how can i insert a ads after 5th post on homepage

Home Forums Support [Resolved] how can i insert a ads after 5th post on homepage

Home Forums Support how can i insert a ads after 5th post on homepage

Viewing 14 posts - 16 through 29 (of 29 total)
  • Author
    Posts
  • #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
    MArc

    #2540809
    Fernando
    Customer Support

    Hi Jmarc,

    Would the ad code be the same after the 5th and 9th posts?

    #2540824
    jmarc

    I don’t understand Fernando …
    Let’s say an add 1 after the 5th post and an add2 after the 9th…

    #2540844
    Fernando
    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_post

    after_ninth_post

    #2540848
    jmarc

    Thank you Fr=ernando but It doesn’t work 🙁

    #2540868
    Fernando
    Customer Support

    I edited and tested the code above. Can you try that instead?

    #2540872
    jmarc

    Thank you Fernando
    How can I put this in the element please ? I’m last

    #2540874
    Fernando
    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 for after_ninth_post

    #2540897
    jmarc

    Thank you but only the 5th one is online , the other no 🙁
    I’m retrying…

    #2540925
    Fernando
    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?

    #2540947
    jmarc

    Yes I did Fernando … don’t know why It doesn’t work …
    Still looking at It

    #2540957
    jmarc

    I guess It’s maybe I Use infinite scroll …
    After testing I’ts not that neither…

    #2541143
    jmarc

    It’s ok … i had to add more articles in a page …
    Thank’s a lot Fernando !

    #2541939
    Fernando
    Customer Support

    You’re welcome, Jmarc!

Viewing 14 posts - 16 through 29 (of 29 total)
  • You must be logged in to reply to this topic.