Site logo

Archived topic

Blog landing page + rel="next"

11 replies · Started by C on May 27, 2021

Viewing posts 1–12 of 12

Hello,

My first site build with GP is nearly finished.

I have been using WP Show Posts to easily control the layout of my Blog landing page but I've noticed I cannot automatically generate the required tags:

<link rel="prev" href="https://www.sitename.co.uk//blog/" />
<link rel="next" href="https://www.sitename.co.uk/blog/page/3/" />

...if I change my Wordpress read settings to show the default blog post page (not a specific page I've designed) then these tags are added.

What is my best solution?

Is there something I can do with WP Show Posts to add these tags (maybe preferred as less effort) OR with recent developments in GP (I started development just before v2.0 came out) could I create a similar blog landing page layout which then may by default include the prev/next tags as needed?

As ever thanks in advance for your time and advice.

Hi there,

can you share a link to the site where i can see the issue

Link and access given. Thanks in advance.

You can change READING > POSTS PAGE setting to NULL or BLOG as needed to switch how posts are displayed.

Hi there,

WPSP was never really intended to be a full blog kind of plugin with pagination etc.. However, you could possible add these links using the following functions:
https://developer.wordpress.org/reference/functions/get_previous_posts_page_link/
https://developer.wordpress.org/reference/functions/get_next_posts_page_link/

I'm not 100% sure it'll work, but you can run a quick test like this:

1. Add a new Hook Element.
2. Set the Hook to wp_head
3. Add this as the Hook content:

<?php
$next = get_next_posts_page_link();
$previous = get_previous_posts_page_link();

var_dump($next);
var_dump($previous);
?>

4. Set the Display Rules to the page with your list.

Do the correct URLs get output on the front-end?

Hello Tom,

Thanks for the update.

I've followed your instructions and applied the hook to the blog page I've manually created and it shows:

string(46) "https://www.myurl.com/blog/page/12/" string(46) "https://www.myurl.com/blog/page/10/"

Forgive me for my lack of experience but the next step would be to try extract just the URLs and format them correctly in the header to read:

<link rel="prev" href="##URL##" />

...and repeat for "next" too right?

I can see that when using the default blog post template (which does all this automatically) it also for the first page, logically, doesn't show a "prev" (as there isn't one) but just the "next" link. So also aware if this logic needs to be included too.

It may be worth then sense checking if it's worth the challenge to get this working with WP Show Posts (as to also not take up too much of your time, unless it's a positive challenge!) or to lean on the default blog template and to try and customise it.

That's correct, you could try this:

<?php
$next = get_next_posts_page_link();
$previous = get_previous_posts_page_link();

if ( $next ) {
    echo '<link rel="next" href="' . $next . '" />';
}

if ( $previous ) {
    echo '<link rel="prev" href="' . $previous . '" />';
}
?>

Let me know if it does it or not :)

That worked well and I can see the tags inserted correctly for next/prev though the blog homepage shows previous as the current page rather than not showing it (as per default setup with Yoast).

A further complication is that the canonical tag for this page is not set correctly as it's showing:

<link rel="canonical" href="https://www.myurl.com/blog/" />

...when technically it's /blog/page/3/

I may be creating a monster here, so apologies (still open to falling back to the default displays and customisation if it's an option).

As ever appreciate your time on helping with this issue.

Blogs are complex which is why it's usually best to allow WordPress to handle the archives, as that's what it was built to do. WPSP was built to show short lists of posts on static pages - not as an alternative to a theme archive page.

What's stopping you from using the built-in archives?

I totally understand about letting Wordpress handling things.

This is my first site using GeneratePress and a learning curve over the last 6 weeks (though generally it's been a great experience and likely I'll switch allegiance fully off the back of this site build so thank you for your efforts to bring this to us!) on using the site library to understand how GP works and is different to my past theme frameworks.

My source site was using WPSP so it guided me in my early development and learning curve, though as things have progressed it may be best that I don't use WPSP in this instance (was always open to this being the case).

It's likely I can lean on the default blog template output (this may be the best result) but could it be that with the features seen in v2 of GP that I can control the layout of the default blog display screen, or would this possibly have the same canonical issue?

The GPP 2.0 Theme building features use the default WP loop and GP templates.
What they do is allow you to build your own content template to be inserted into the loop - instead of having to bake your own content.php template.

Thanks for the update David.

I think then a better approach would be for me to switch to the default blog posting display for the site migration. Post launch, if needed, I can investigate the new features to control the layout.

Appreciate the time the team has taken to advise.

Sounds like a good approach.
Glad we could be of some help

This archived topic is closed to new replies.