Jump to content

how to set the latest id as a new page name?


leoric
 Share

Recommended Posts

name*
Any combination of letters (a-z), numbers (0-9), dashes or underscores (no spaces).

i use chinese language, i have to translated page title to english every time.

its a problem for me  :(

if it could be this?

when i dont type anything in this option system automatic insert the id(the last page id +1 )

is there have some solutions?

thank you.

Link to comment
Share on other sites

This should be fairly easy to do with a simple module. These two posts should get you going:

There are several different possible methods detailed in here:

http://processwire.com/talk/topic/1908-automatically-generating-new-page-names/

This post is less relevant since it is for pages created with the API, but might be worth a read still:

http://processwire.com/talk/topic/4571-id-based-slug-instead-of-title/

  • Like 1
Link to comment
Share on other sites

thank you,adrian  , your reply is very helpful.. 

and thanks for ryan  in here:

http://processwire.com/talk/topic/1908-automatically-generating-new-page-names/?p=17887

i do this and get what i want:

open "wire\modules\process\ProcessPageAdd\ProcessPageAdd.module":

find this : "public function init()"  and add this line 

$this->addHookBefore('InputfieldPageName::render', $this, 'hookRender'); 

then add this function in this class:

	public function hookRender(HookEvent $event) {
	  if($this->process != 'ProcessPageAdd') return;
	  $id=$this->pages->find("include=all")->last()->id+1;  //get the latest id
	  $inputfield = $event->object;
	  if(strlen($inputfield->attr('value'))) return; 
	  $inputfield->attr('value', $id);  
	}

ok,that's all.

thank you everyone!

Link to comment
Share on other sites

Glad to help.

Just one thing - from what you describe, it sounds like you are editing the core ProcessPageAdd module. You don't want to do this, because you'll have to make these changes again every time you upgrade PW. Instead you should create your own simple module using that code.

Read here for a tutorial on creating your own module:

http://wiki.processwire.com/index.php/Module_Creation

  • Like 2
Link to comment
Share on other sites

Glad to help.

Just one thing - from what you describe, it sounds like you are editing the core ProcessPageAdd module. You don't want to do this, because you'll have to make these changes again every time you upgrade PW. Instead you should create your own simple module using that code.

Read here for a tutorial on creating your own module:

http://wiki.processwire.com/index.php/Module_Creation

wow, it's so cool.......i'm very  very happy...

yes,i did it.

this is my first time to make a module.  

thank you very much,adrian .

  • 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

  • Recently Browsing   0 members

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