Forum

Thread tagged as: Question, Add-on-development, Blog

How do I remove the date in a blog post URL

I have the blog add on setup and all works fine but I am wondering if there is a way to remove the date stamp in the URL so the URL would just be '/blog/post-title' and not 'blog/2016-09-23-post-title'.

That said, is there an SEO advantage to having the date stamp in the URL?

Many thanks in advance.

Andrew

Sarah Whittle

Sarah Whittle 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You can edit the slug format on the Settings page.

Hi Drew, I did this so it was just {postTitle} instead of %Y-%m-%d-{postTitle}, yet the date is still being added. Would it only take effect on new blog posts?

Rachel Andrew

Rachel Andrew 394 points
Perch Support

Yes - we don't want to break your old URLs!

Cool, thanks Rachel

One other question RE the blog posts, they do not seem to get added to the sitemap using the technique I found on the Perch Site, just the main site pages.

Is there a way of automatically getting them added?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you show us what you're doing?

I followed the Perch tutorial at https://solutions.grabaperch.com/html-and-css/how-do-i-create-a-google-sitemap

This works spot on for pages I create in the CMS but I was hoping it would also index blog posts as we wish to do a lot of blogging.

Thanks Andrew

Rachel Andrew

Rachel Andrew 394 points
Perch Support

You would need to use perch_blog_custom to get blog posts, otherwise it is the same process.

Thanks Rachel

Where would I add this code?

Thanks Andrew

Drew McLellan

Drew McLellan 2638 points
Perch Support

It would go in the page that you are using for your sitemap.

This is what I have at the moment... Are you saying I need to add perch_blog_custom to this?

<perch:before><?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9"> </perch:before> <url> <loc>https://www.whittledesignstudio.com<perch:pages id="pagePath" /></loc> </url> <perch:after> </urlset> </perch:after>

Drew McLellan

Drew McLellan 2638 points
Perch Support

Is that your template? You'd need to add it to the page, not to the template.

Yes I saved a file called sitemap.php and saved this in templates/navigation as per the instructions on the Perch link above and the pages are being added to the sitemap. I am now a little confused as to what page this code needs to be added and where.

Thanks Andrew

Rachel Andrew

Rachel Andrew 394 points
Perch Support

The page sitemap.php should not be saved into your templates folder, that is not what the documentation says to do.

You should have a page in the root of your site which has the call to perch_pages_navigation. Below this you need to add your code to get your blog posts using perch_blog_custom.

Sorry, the file saved in templates/navigation is the sitemap.html file and I do have the sitemap.php in the root with the following code...

<?php header('Content-type: application/xml'); include('perch/runtime.php'); perch_pages_navigation(array( 'template'=>'sitemap.html', 'flat'=>true )); ?>

So the question is still, where do I add perch_blog_custom

Drew McLellan

Drew McLellan 2638 points
Perch Support

You'd do something like:

    PerchSystem::set_var('blog_pages', perch_blog_custom([
        'template' => 'blog_sitemap.html',
    ], true));
    perch_pages_navigation(array(
        'template'=>'sitemap.html',
        'flat'=>true
      ));

and then in your sitemap.html you'd output the blog pages where you want them:

<perch:after>
    <perch:pages id="blog_pages" encode="false" />
    </urlset>
</perch:after>

So in my sitemap.html file that is save din my templates I would have the following?

<perch:before><?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9"> </perch:before> <url> <loc>https://www.whittledesignstudio.com<perch:pages id="pagePath" /></loc> </url> <perch:after> </urlset> </perch:after>

<perch:after> <perch:pages id="blog_pages" encode="false" /> </urlset> </perch:after>

I am still unsure where the first set of code goes in relation to what I currently have which is...

<?php header('Content-type: application/xml'); include('perch/runtime.php'); perch_pages_navigation(array( 'template'=>'sitemap.html', 'flat'=>true )); ?>

Rachel Andrew

Rachel Andrew 394 points
Perch Support

It goes into your sitemap.php. You have:

<?php header('Content-type: application/xml'); 
include('perch/runtime.php'); 
perch_pages_navigation(array( 'template'=>'sitemap.html', 'flat'=>true )); ?>

Drew has given you the code you need to use instead of just the call to perch_pages_navigation.

PerchSystem::set_var('blog_pages', perch_blog_custom([ 'template' => 'blog_sitemap.html', ], true)); perch_pages_navigation(array( 'template'=>'sitemap.html', 'flat'=>true ));

Sorry Rachel, I'm not a Dev so this is all too confusing. I tried just replacing my code with what Drew supplied and I get an error on the page, then I added it to the code I have and I get another error. So here is what I have at the moment...

<?php header('Content-type: application/xml'); include('perch/runtime.php'); perch_pages_navigation(array( 'template'=>'sitemap.html', 'flat'=>true ));

PerchSystem::set_var('blog_pages', perch_blog_custom([ 'template' => 'blog_sitemap.html', ], true)); perch_pages_navigation(array( 'template'=>'sitemap.html', 'flat'=>true ));

?>

Rachel Andrew

Rachel Andrew 394 points
Perch Support

We really can't go a lot further than what we have done, which is give you the exact code you need. You need to be able to do basic troubleshooting and write simple PHP if you want to do this.

There are troubleshooting tips here https://docs.grabaperch.com/perch/help/

Basics of PHP here: https://docs.grabaperch.com/perch/building/servers/how-do-i-get-started-with-php/

We have Perch developers here many of whom are happy to help on existing projects https://grabaperch.com/developers