Jump to content

Custom urls for pages


Manaus
 Share

Recommended Posts

Hello, I'm trying to get a page like /20141214-my-url-title, but seems like either it's a date or it's a title.

For example, I tried Y-m-d-title, and I got 2014-12-14-310231sundayamerica-new_york which is nice in its own right, but not what I'm currently looking for.

Thanks for any suggestion...!

Link to comment
Share on other sites

I don't understand clearly what you want.
If you want to create a page by API inside a template you can do this:

$p = new Page();
$p->template = 'basic-page';
$p->parent = $pages->get(1);
$p->name = date('Ymd').'-my-url-title';
$p->save();

to get a page with a specific name use:

$pages->get('20141214-my-url-title');
//or
$pages->find('20141214-my-url-title');

Does this help? If not please explain more clearly what you want to do.

  • Like 2
Link to comment
Share on other sites

I think Manaus is talking about "Name format for children" option under Family tab of the template when only 1 template for children is allowed. Availiable options are described here. But me too would want them to be more rich, maybe something like in this Adrian's module.

Edit: Checked it out and did not find a way to combine date and title (with or without custom text in between). If anything but "PHP date format" is in the field we get what Manaus showed in his post: something like 15313431mondayeurope-moscow.

Edited by Ivan Gretsky
  • Like 3
Link to comment
Share on other sites

About "Name format for children" option
This option is still in development and not very well correct described (doesn't work properly too)
Until now you have 3 options:

  • If you type 'title' (without quotes) in the setting field you will get a page title 'untitled', because there doesn't exist a title if you autogenerate the page.
    from the 2nd page up you will get the title 'untitled-[n]' whereas n starts counting not at 1 but at the total number of sibling pages under this parent
    name is always date('Y-m-d-h-i-s') example '2014-12-15-04-10-30'
  • If you type any other character than these (-_ a-zA-Z0-9) you will get a string generated with the date() function (sometimes weird stuff)
  • If you type a string with allowed characters (-_ a-zA-Z0-9) you will get this string as a prefix. Same as above with the counter [n]

Source of this information: wire/core/Pages.php Line 700 something

Edited by kixe
  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...