Custom Content after X posts?

Home Forums Support Custom Content after X posts?

Home Forums Support Custom Content after X posts?

  • This topic has 13 replies, 2 voices, and was last updated 8 years ago by Tom.
Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #175963
    Kristian Foshaug

    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

    #175977
    Kristian Foshaug

    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.

    #175995
    Tom
    Lead Developer
    Lead Developer
    #176007
    Kristian Foshaug

    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

    • This reply was modified 8 years, 1 month ago by Kristian Foshaug.
    • This reply was modified 8 years, 1 month ago by Kristian Foshaug. Reason: fixed the code-tag
    • This reply was modified 8 years, 1 month ago by Kristian Foshaug. Reason: fixed the code-tag
    #176117
    Tom
    Lead Developer
    Lead Developer

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

    #176139
    Kristian Foshaug

    That code completely broke the layout.

    broken

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

    #176205
    Tom
    Lead Developer
    Lead Developer

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

    #176219
    Kristian Foshaug

    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).

    #176522
    Tom
    Lead Developer
    Lead Developer

    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>
    #176548
    Kristian Foshaug

    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.

    #176610
    Kristian Foshaug

    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).

    #176730
    Tom
    Lead Developer
    Lead Developer

    Hmm, that’s because you need to make sure you’re only adding it to the first page along with this check:

    http://wordpress.stackexchange.com/questions/31065/how-to-determine-if-im-on-the-first-page-of-pagination

    Thinking about this – why not just add a post with the “Link” post format (or Aside etc..) and then adjust the date to have it display in a specific position?

    Might be a little less hassle with the same result.

    #176799
    Kristian Foshaug

    Thanks – that pagination checked worked. 🙂 Now only the issue with the gap in the masonry remains.

    #176955
    Tom
    Lead Developer
    Lead Developer

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

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