• Hi,

    How can we loop the previous and next post block’s functionality so instead of getting to the lat post and ending, it loops back to the first post?

    Or if this is not possible, can we at least display either control when it disappears at the first or last post as an inactive UI element? I’ve tried with CSS but nothing’s working (so far), but maybe I’ve not done this completely right. I’ll paste the code I’ve tried for this fall back solution but any information or ideas appreciated, thank you!

    /* Show the previous post navigation link at all times */
    .wp-block-post-navigation__prev-link {
      display: block !important;
    }
    
    /* Adjust the styling of the inactive previous post navigation link */
    .wp-block-post-navigation__prev-link.inactive {
      opacity: 0.5;
      /* Additional styling properties here */
    }
    
    /* Show the previous post navigation link at all times */
    .post-navigation-link-previous {
      display: block !important;
    }
    
    /* Adjust the styling of the inactive previous post navigation link */
    .post-navigation-link-previous.inactive {
      opacity: 0.5;
      /* Additional styling properties here */
    }
Viewing 10 replies - 1 through 10 (of 10 total)
  • Moderator Felipe Santos

    (@foosantos)

    Hi @davidhc,

    I not really sure if I understood what you’re referring to. Can you provide an example of what you’re trying to do?

    Thread Starter davidhc

    (@davidhc)

    Hi @foosantos,

    Yes sure, so for example take the most recent post on this site:

    Call for testing of the new Font Library – Gutenberg Times

    At the end of the article/post you get the navigation links to go to the previous post chronologically, but not a ‘Next’ post UI item. But of course, clicking to a previous post would then show both navigation options to go either way.

    What I want to to is make it so if you are at the first or last post, you can continue cycling through the entire set you have on the site or within that category.

    But perhaps my use case would be of more help, I’m adding posts that hold an artist’s work displayed on a query loop. Single post template inherits that and we show one post, but it’s the one selected. I then want to be able to scroll throughout all the images. OR at least have some form of UI nudge like not entirely removing the ‘Next’ link for instance and making it appear inactive.

    Sorry if this is a long reply, hopefully it makes sense. Cheers!

    Thread Starter davidhc

    (@davidhc)

    I found a website using WP that illustrates this perhaps slightly more clearly, although perhaps the site’s build isn’t that new itself it’s still the core WP functionality I’m looking at.

    https://cecilybrown.com/untitled/

    Link above shows the user’s posts displayed oldest to newest by the looks of it, but it also shows only the ‘Next’ navigation UI is viewable.

    Hey @davidhc ! I did a quick search, and found on the plugin below. Is this something that looks like what you’re trying to do?

    Thread Starter davidhc

    (@davidhc)

    Hey @properlypurple,

    Yes that one absolutely looks like it should do what’s needed but unfortunately it doesn’t seem to have any affect when activated.

    To be fair the plugin says it hasn’t been tested on the last 3 major WP releases, so perhaps it’s just not an option when using Gutenberg/Twenty Twenty Three.

    I’ve read I could potentially do this with some PHP edits but I wanted to keep this as much using just TT3 as possible really, apart from using some plugins of course ??

    Hi again ??

    I did some more digging, and it looks like you need to use the PHP template tags provided by the plugin, and put them in your templates. The plugin’s page has examples

    <div class="alignleft">
        <?php c2c_previous_or_loop_post_link(); ?>
    </div>
        
    <div class="alignright">
        <?php c2c_next_or_loop_post_link(); ?>
    </div>

    You can combine these with a plugin like Lazy blocks, which will let you make custom ‘Next’ and ‘Previous’ blocks out of the above PHP/HTML code. You can then put these custom blocks in a template inside the site editor.

    Thread Starter davidhc

    (@davidhc)

    Thanks for the heads up @properlypurple, I totally missed that section on the Loop nav plugin page. I’d tried the Lazy Blocks plugin previously actually, just had a go now but couldn’t quite get it all to work. So it’s probably becoming a bit of a waste of time at this stage, I’ll have to return to it in future.

    Thanks again ??

    If you’re still going to try this with Lazy blocks, the options from the following screenshot worked in my tests.

    Thread Starter davidhc

    (@davidhc)

    This is ideal, thank you @properlypurple ?? The power of the WP community!

    That totally achieves what we needed for this site, I edited the PHP so it displays custom text instead of the post title if anyone else needs this in future:

    <?php c2c_next_or_loop_post_link('%link >', 'NEXT'); ?>

    Do you guys think there’s any problems in that the Loop Post Nav plugin hasn’t been updated in 3 years? Or you know, in general is it a security/stability risk to warrant concern? ??

    I’m glad this worked out ??

    Do you guys think there’s any problems in that the Loop Post Nav plugin hasn’t been updated in 3 years?

    It doesn’t look like the support forum for the plugin is very active. The plugin seems simple enough, but you can also get in touch with the author to get some more clarification. There is a ‘Links’ section on the plugin page, with links to Github, and the author’s site.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘How to Loop ‘Previous Post’ and ‘Next Post’ block’s functionality’ is closed to new replies.