SiNNuT Posted July 9, 2011 Share Posted July 9, 2011 As far as i can tell the page id isn't shown in the P21 admin area. I think it would be useful to do so. Sometimes you want to get pages by id. If you have db access you can look them up but this isn't necessarily the case for all people working on a site, and it's fields and templates. Let's say i want to show a couple of links to specific pages in my footer include. At the moment i know the urls but the pages could move around in the future, including changes in parent. To avoid possible dead links the best way is to get the pages by id right? Something like: <a href="<?=$pages->get(1)->url?>">FAQ</a> <a href="<?=$pages->get(2)->url?>">Contact</a> That way it is just set and forget, wherever you move your pages. If there is a better approach i would like your comments. Link to comment Share on other sites More sharing options...
WillyC Posted July 9, 2011 Share Posted July 9, 2011 ID is in the address bar when you are editing a page: /processwire/page/edit/?id=1 Link to comment Share on other sites More sharing options...
ryan Posted July 11, 2011 Share Posted July 11, 2011 That's correct that the ID should be in the address bar, visible in the URL (at least, that's where I get it). We also used to have the ID displayed in the interface in the far right corner, but the new Save button is now covering that ID. Perhaps we should find another location to put the ID back in. Good question about whether to use the ID or the path. Here are some points on that: Using the path is better for clarity in your API calls. I rarely use the ID for API calls (too much work). If the page is going to move at some point (or it better suits your style), you are right that using the ID is preferable because no on-site links will be broken. There can be a slight speed advantage to using the ID over the path, but at a loss of readability. Moving pages in your nav breaks off-site links regardless. Better not to move main pages after launch. If all you are getting from the page is the URL, and you are building non-dynamic nav, consider just hard coding it (for the most efficiency). Don't load extra pages if you don't have to. Accounting for pages moving is the only reason I would use IDs in the example you posted. And that's a perfectly good reason to do it. But that particular example wouldn't translate well to using paths because it would be redundant: <a href='<?=$pages->get('/faq/')->url?>'>FAQ</a> <a href='<?=$pages->get('/about/contact/')->url?>'>Contact</a> The above is redundant and unnecessary, because you could just do this, which is much more efficient (no API calls necessary): <a href='/faq/'>FAQ</a> <a href='/about/contact/'>Contact</a> I run my dev sites off subdirectories and need them to be compatible between dev and live. So I reference the root URL in my sites when coding static navigation. But this is just as efficient as the example above. <a href='<?=$config->urls->root?>faq/'>FAQ</a> <a href='<?=$config->urls->root?>about/contact/'>Contact</a> Link to comment Share on other sites More sharing options...
webweaver Posted September 6, 2013 Share Posted September 6, 2013 Brand new to PW (today). This is one of the first questions I had. Would be nice to have the id in parenthesis next to the page name (like ModX) vs having to click on the page name, then edit to retrieve the id in the url. Link to comment Share on other sites More sharing options...
Soma Posted September 6, 2013 Share Posted September 6, 2013 Or you can hover over the edit link to see id. Link to comment Share on other sites More sharing options...
Soma Posted September 6, 2013 Share Posted September 6, 2013 Just created a little helper module http://processwire.com/talk/topic/4432-page-list-show-page-id/ 1 Link to comment Share on other sites More sharing options...
webweaver Posted September 7, 2013 Share Posted September 7, 2013 I am pretty excited about PW, and witnessing the support from the forum puts me in a state of pure bliss. Thank you Soma for the module - works great! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now