Jump to content

[SOLVED] - Blog Post Path Format Query


ridgedale
 Share

Recommended Posts

Reference: PW 3.0.62 and uikit3 based site using the Regular-Master profile.

The issue is that blog posts for the particular site in question are automatically formatted as /blog/<blog-post-title>. It is evident the path format should have been configured as /blog/<year>/<month>/<blog-post-title>.

Please could someone advise whether or not it is possible to change the path format for the blog posts of an existing active site that uses the regular profile?

Any assitance would be greatly appreciated.

Edited by ridgedale
Issue resolved
Link to comment
Share on other sites

Hi Robin,

Thank you for your reply and the suggestion. I realise belatedly my original proposal for the blog post path to be /blog/<year>/<month>/<blog-post-title> doesn't prevent the possibility of potential of clashing post titles. I now believe it would be better to simply add the blog post id as a prefix to the post title such as is deployed in this forum.

e.g.

https://processwire.com/talk/topic/-

and therefore achieve something along the lines of:

/blog/<post-id>-<post-title>

but as on the Processwire Forum only display the <post-title> on the actual post page.

That way posts could be made using the same title and be uniquely identified.

Do you or anyone else know how this is achieved?

 

Edited by ridgedale
improved clarity
  • Like 1
Link to comment
Share on other sites

Edit the Parent template and look under the "Family" tab and you'll see the "Name format for children"

nameformat.thumb.jpg.143319f84eea6ca7d83ce1b462db25dc.jpg

Try entering "id-title" without quotes in that field and see if it works.

As described on http://processwire.com/api/modules/process-template/ 

You might also need http://modules.processwire.com/modules/page-rename-options/

Hope that helps

 

  • Like 1
Link to comment
Share on other sites

Thanks for your suggestions, gmclelland.

I don't see the Name format for children field you are referring to. I've attached screen grabs of what I see when I view the blog and blog-post templates' Family tab.

I would be happy to delete and manually reinstate the posts, if necessary, and would like to avoid using a module, if possible.

Any thoughts?

blog-post-family.png

blog-family.png

Link to comment
Share on other sites

Doh! Sorry, my eyes must be going! :(

When I typed in simply id-title the page path was returned as exactly that:

/blog/id-title/

When I changed the text to $id-$title the following was returned:

/blog/3419-313431fridayeurope-london/

I am assuming 3419 is the page id and the hyphen returned is correct but I'm not sure what the rest is referring to. Is it a timestamp in seconds followed by the day name and time zone? If that is the case $title is not the variable I'm looking for.

Any further thoughts?

Link to comment
Share on other sites

A new post with $id $title typed into the Name format for children field and saved produced:

/blog/0319-310331fridayeurope-london/

That does not make sense because I would have expected $id to have incremented by 1 and the 310331 cannot likewise be a timestamp as the figure has actually reduced. :?

I've tried to check the database to see where the data is actually stored but have not been able to locate it. :(

Link to comment
Share on other sites

Hrmm... I tried it on a site and couldn't get it to work.  You might need to go the module or hook in your ready.php route.

I also don't think you are seeing the correct id of the new page.  We are probably seeing a temp page id, since the page hasn't been created yet.

On a past site, I choose to simply not worry about the page name.  When a new page is created and the name is not unique, an incrementing number will be appended to the end of it until it is unique.

To make it easier to view the news postings in the page tree, I edited the template's under the "Advanced" tab > "List of fields to display in the admin Page List" setting to include the date.

Someone else may chime with some other better ideas.

Link to comment
Share on other sites

Thanks for all your input, gmclelland. It is very much appreciated.

After messing around creating numerous posts I have come to the conclusion that entering $id into the Name format for children field returns a random (currently 4-digit) number (id) which would be fine except that when the Sort settings for children > Children are sorted by is set to date (default setting) and the reverse sort direction? setting is checked the blog posts generally are sorted correctly by date except for blog posts created on the same day. Blog posts created on the same day appear to be being sorted by the name which in this case is the randomly generated $id. If the randomly generated id is lower than an earlier post on the same day, it will not appear in the correct sort order.

The solution to that issue is resolved by changing the Sort settings for children > Children are sorted by is set to created instead. Then the posts will appear in the correct sort order. 

My first thought is why on earth is the $id being generated as a random instead of incremental number?!

Secondly, please could someone explain where the blog post and page data are stored in the database? I've looked and must be missing something because I can't find the data.

 

 

 

Link to comment
Share on other sites

 

4 minutes ago, ridgedale said:

Thanks for all your input, gmclelland. It is very much appreciated.

Your welcome.  I'm still learning too!

4 minutes ago, ridgedale said:

My first thought is why on earth is the $id being generated as a random instead of incremental number?!

Looks like it generates and assigns a random id here https://github.com/processwire/processwire/blob/6241fd67300c456c225cb336a3de27acab167b2d/wire/core/PagesEditor.php#L343 until the page is saved.  Probably to make sure the page name is unique?

9 minutes ago, ridgedale said:

Secondly, please could someone explain where the blog post and page data are stored in the database? I've looked and must be missing something because I can't find the data.

Pages are stored in the "pages" table.  The field data is stored in each field_fieldname table.  Each field gets it's own database table.

Link to comment
Share on other sites

Thanks again, gmclelland.

15 minutes ago, gmclelland said:

Pages are stored in the "pages" table.  The field data is stored in each field_fieldname table.  Each field gets it's own database table.

Now it makes sense. :)

However that does mean that my solution does not actually work for adding back old posts because the created date is actually the present date and time. The problem with when the Sort settings for children > Children are sorted by is set to date (default setting) is that zeroed time-stamps are generated. So posts set as being on the same day end up being randomly sorted. :(

I don't know if it possible to change date to include H:i:s. I'll have a look at that.

Update: No, H:i:s cannot be added in the date field. :(

Edited by ridgedale
Update following date check
Link to comment
Share on other sites

Hey @ridgedale. I am the author of the Blog module. I might be able to offer a couple of suggestions (1. Manually creating the /year/month/ folders; I have tested and it works {see screen below}; 2. Hooking into Page path.).  Briefly ask your question again in the module's support forum (will help others get the context) and I'll walk you through the suggestions.

blog-change-url-1.thumb.png.52b5d86a1a2497ebe758b8f54c7f44d0.png

 

Link to comment
Share on other sites

Hi kongondo,

Thank you for your reply. However,

On 17/01/2018 at 7:40 PM, ridgedale said:

Reference: PW 3.0.62 and uikit3 based site using the Regular-Master profile.

Unless I'm mistaken, I'm not using the Blog module. The Blog module has not been added under wire/modules or site/modules.

Link to comment
Share on other sites

39 minutes ago, ridgedale said:

Thanks again, gmclelland.

Now it makes sense. :)

However that does mean that my solution does not actually work for adding back old posts because the created date is actually the present date and time. The problem with when the Sort settings for children > Children are sorted by is set to date (default setting) is that zeroed time-stamps are generated. So posts set as being on the same day end up being randomly sorted. :(

I don't know if it possible to change date to include H:i:s. I'll have a look at that.

Update: No, H:i:s cannot be added in the date field. :(

I've also tried adding a new datetime field but that does not work either. When I select the date output format as yyyy/mm/dd the field is actually formatted as yyyy-mm-dd. Plus irrespective of what is selected for the time output format the time is rendered as a zeroed time - 00:00:00! :(

A biut of a headache at the moment!

Link to comment
Share on other sites

On my "news" template I have a datetime field for "published_on" that I use in the parent's template(news-index) "Sort settings for children" (reversed sort is checked).

I'm pretty sure the sorting works for news items posted on the same day.

Link to comment
Share on other sites

I realise that but I have to copy and paste a long list of old posts from another CMS into PW3, so it is not possible to simply work through the list and add the old posts unless I audit the list and sort it into timestamp order before I start.

If I could create a time field that can be manually editted that might help.

Link to comment
Share on other sites

2 minutes ago, ridgedale said:

If I could create a time field that can be manually editted that might help.

That's why I created a posted_on datetime field.  I manually entered the date and time into that field since it may be different than time the post was published in Processwire.

Link to comment
Share on other sites

9 hours ago, gmclelland said:

That's why I created a posted_on datetime field.  I manually entered the date and time into that field since it may be different than time the post was published in Processwire.

Thanks, gmclelland. Selecting the No date/time picker option allowed the editing of the time. Interestingly though, if the date only is changed the time defaults to the current time, so if the field content is changed and the time is important both the date and time must be entered and saved.

Did you remove the original date field from the template as well?

 

Link to comment
Share on other sites

8 hours ago, kongondo said:

Oops! My bad. 

Hi kongondo,

No problem. However, as a senior member of the community, I wonder if you might know how the posts in this forum are generated with sequential ids followed by a dash and then the post title. Entering $id into the Name format for children field returns a random (currently 4-digit) number (id) which is not what I'm after.

Any assistance on that would be greatly appreciated.

 

Link to comment
Share on other sites

It just seems like this never really worked as intended, or maybe stopped working as expected.

However, I just installed kixe's module mentioned earlier, and when I tried this children name format, it works:

date(Y-m-d) title id

gives me

2018-01-20-here-we-go-again-1043

 

  • Like 1
Link to comment
Share on other sites

On 20/01/2018 at 5:40 AM, ridgedale said:

That way posts could be made using the same title and be uniquely identified.

Nothing extra is needed to achieve this. If you create a page that has the same title as another page under the same parent then by default PW will automatically add a digit to the end of the page name to make it unique. Unless you have a need for something different it's best to just leave it at that.

But if you want to prepend the page id to the page name you can do it with a hook in /site/ready.php:

$pages->addHookAfter('saveReady', function (HookEvent $event) {
    $page = $event->arguments(0);
    if($page->template != 'blog-post') return; // Only for the blog-post template
    if(!$page->id) return; // Skip pages that are brand new and aren't yet populated with data
    // If the page name doesn't start with the page id
    if(strpos($page->name, (string) $page->id) !== 0) {
        // Prepend the page id to the page name
        $page->name = $page->id . '-' . $page->name;
    }
});

 

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...