Jump to content

P21 Page ID in admin


SiNNuT
 Share

Recommended Posts

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

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

  • 2 years 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...