Site logo

Archived topic

Hook after certain number entry content

8 replies · Started by Schiller Smith on January 25, 2022

Viewing posts 1–9 of 9

Hi Guys. Would be greatful for your help. I am using the hook "generate_after_entry_content" and find it very useful, but I lack of choosing the place number where the hook is to be shown. For example, I want it to be displayed after each third, of forth post but not in the every one. Is there any solution with elements? Thanks

Hi there,

You could use a PHP Snippet to set a condition eg.

global $wp_query;
if ( 0 == ($wp_query->current_post) % 3 ) {
    echo 'i am every third post';
}

So the % 3 means modulus 3 - in theory this will display content on every 3rd post

Hi David. Thanks for your feedback. Where should I paste this code? For example, I have such kind of a code in my "hook element" field

<? if (!empty($somename_active)): ?>
<iframe id="frames" src="https://www.site.com/ad/?phrase=somename" frameborder="0" width="100%" height="450px"></iframe>

it is used to be displayed "generate_after_entry_content"

Thanks

Like so:

<?php
global $wp_query;
if ( ( 0 == ($wp_query->current_post) % 3 ) && ( !empty($somename_active) ) ) {
    ?>
    Your IFrame code here
    ?php
}

David, I am doing exactly the same, but there is a critical error on the the site.

Hi there,

We can modify David's code to fix the syntax issue/s.

Try using this as reference:

<?php
global $wp_query;
if ( ( 0 == ($wp_query->current_post) % 3 ) && ( !empty($somename_active) ) ) {
?>
   // your <iframe> code here

<?php
}
?>

It was missing a < and ?> syntax. :)

Thanks. Now it doesn't error the page, but displays nothing. I am trying to use it on some certain category listing.

I seem to find the problem. I removed the part ( !empty($somename_active) and it works! Thanks for your help!

Thanks for letting us know. No problem. Glad you got it sorted. :D

This archived topic is closed to new replies.