Site logo

Archived topic

Custom Content after X posts?

13 replies · Started by Kristian Foshaug on February 28, 2016

Viewing posts 1–14 of 14

Does GeneratePress support in any way an option to add content after X posts? For instance, we want to add a custom content banner between the 5th and 6th post. Currently running masonry so that we have one large post, then two smaller posts per "row".

Basically something similar that Rockpapershotgun does with their video-banner a few posts down: https://www.rockpapershotgun.com/

our site: http://www.spillhistorie.no

I found this way: http://wpsites.org/insert-ad-codes-first-second-nth-post-10364/ - perhaps not the best one but...

This leaves a small problem when using Masonry - when making a "full width" custom post, the masonry on the posts above will be uneven if the two posts are not similar lenght, and thus leave a gap before the next full width post comes.

I've updated it now so that the issue is live.

Using the second alternative, Method two.

The inserted post is the two-column one below the gap ("Sjekk vår dekning...")

<?php if ( have_posts() ) : $count=0; ?>
 
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); $count++; ?>
    <?php get_template_part( 'content', get_post_format() ); ?>
    <?php if ($count == 2) : ?>
        Ad Codes after 2nd post
    <?php endif; ?>
<?php endwhile; ?>
 
<?php else : ?>
    <?php get_template_part( 'content', 'none' ); ?>

example

Can you try the other code that I posted? It should be a better option than changing the loop directly.

That code completely broke the layout.

broken

(i'm editing index.php as suggested on that page)

Hmm, do you want this inserted div to be full width, or the same as the other posts?

Both - I would like to be able to have some small and some full width. The small ones work perfectly with the code I provided, but as mentioned, the masonry above the full width leaves a gap as shown in the image (because the above post isn't "long" enough).

For full width, wrap your content in this:

<article class="masonry-post width6">
    Your content
</article>

For medium width:

<article class="masonry-post width4">
    Your content
</article>

For small width:

<article class="masonry-post width2">
    Your content
</article>

I'm probably bad at explaining, sorry :/

I know how to get the proper widths, but the issue is that the posts above the inserted one does not "fill" the masonry vertically - as shown in the first screenshot I shared. I did try to use your suggestion above, but the same thing happens.

I just noticed another bug using this - when using the "display more posts" at the bottom of the page, the added block will display again (just go to the site, scroll down, and click load more - and it will repeat endlessly).

Thanks - that pagination checked worked. :) Now only the issue with the gap in the masonry remains.

Is it currently on your site or have you taken it down?

This archived topic is closed to new replies.