Site logo

Archived topic

Page Hero and Dynamic Content

7 replies · Started by Konstantin on July 7, 2021

Viewing posts 1–8 of 8

I'm using the Page Hero element to display a latest post at the top of an Archive for a blog and it almost works the way I need it to. Although the data being pulled is supposed to be for a current post, the Archive page (/blog in my case) is not actually a post. However, I am able to pull all the data I need exactly from the latest post with the exception of Title. I'm able to pull Featured image, publish date, author and even the title links to the correct post. But the title itself just says Blog. Is there a way to make this work 100%? Thank you.

Hi there,

I'm not exactly sure what you want for the Blog. Did you want to display an image?

If yes, you'll have to exclude Blog page from the current Page Hero element you have and make a new Page Hero element w/ display rule specifically for the Blog page.

You then add its own custom image because Blog page doesn't have featured image like how you assign it on post pages.

Hi. Perhaps this is working not as intended, but here's the setup:

I'm trying to display the latest post on a Blog archive (built in Toolset) at the very top, using GP Page Hero. The dynamic data shown while building the container allow me to add the following:

  • Dynamic Background Image > Featured image, Dynamic Link > Post, Source > Current post
  • Dynamic text type > Post date, Data type > Published date
  • Dynamic text type > Post author name, Dynamic link type > Author archives
  • Dynamic text type > Title, Dynamic link type > Single post

Literally all of the above is working and the post referenced is in fact the latest post somehow, but the Title is of the Archive page (Blog) and not the post itself. But the Dynamic link type > Single post for the title is correct. The links for the Featured image and Author archives are correct too.

Thanks

Hi there,

you would need to create a shortcode to output the_title - add this PHP snippet to create the shortcode:

add_shortcode('latest-post-title',function(){
    return get_the_title();
});

Then you can add the [latest-post-title] in your Headline block

Hi David,

Yes, that definitely got me the title! Is there an easy way to return the title with a link to the post?

Thanks

Aah change the snippet to:

add_shortcode('latest-post-title',function(){
    return sprintf(
        '<a href="%1$s">%2$s</a>',
        get_permalink(),
        get_the_title(),
    );
});

Fantastic! Thanks a lot

You're welcome

This archived topic is closed to new replies.