Pregunta

I need to hook a post from Custom post type after every 5 posts from the main blog posts in the loop. Please suggest me with some code.

¿Fue útil?

Solución

May be there in no hook for that or i don't know about that, But You can do something like this:-

<?php
$postnum = 0; // Set counter to 0 outside the loop

if (have_posts()) : 
    while (have_posts()) : the_post();

        // Do regular stuff

        $postnum++; // Increment counter

        if ($postnum % 5 == 0){ // If the remainder of the counter value divided by 5 equals zero
            // Do special stuff
        }

    endwhile;
endif;
?>

Hope this will help you.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top