Jump to content

Build a navigation by ID


KentBrockman
 Share

Recommended Posts

Hey there,

currently we are developing our first project with Processwire. Coming from MODX Revolution we are absolutely impressed by the simplicity and power of processwire.

...and the speed of the Admin :-)

All things are running great, except of one requirement. We got stuck on building a navigation by ID. Means we want to get a list of defined pages.
For example: "Show a list of pages with the ids 1, 1001, 1003, 1007"
 

$homepage = $pages->get("id=1,1001,1003");


Everything we tried (find, array and so on) didn't work.
What are we doing wrong?

Or is there a other "best-practice" to build a list like this?

Thank you so much for your support and all your efforts on this great project!

Link to comment
Share on other sites

Hi KentBrockman, welcome to ProcessWire.

There are two reasons why it doen't work:

1) $pages->get will return only one page. If you want multiple pages, you have to use $pages->find which returns a PageArray.

2) You need the OR selector: id=1|1001|1003

So you could try this:

$myPages = $pages->find("id=1|1001|1003");
foreach ($myPages as $p) {
  echo $p->title;
}

To make this more dynamic, you could add a checkbox field to the templates of pages you want to list, let's call the field "show_nav".

Then check the checkbox on the pages you want to appear and update the code:

$myPages = $pages->find("show_nav=1");

Of course this is only one possible solution out of 100 (infinity), with ProcessWire you have no limits :)

  • Like 3
Link to comment
Share on other sites

100 sounds like a limit to me...

edit:

another option would be to have a hidden page called "navigation" with a pageFieldType multiple in it where you could list the pages.

97 to go :)

  • Like 3
Link to comment
Share on other sites

Dumb question here:
Where can I find ID of the page in the backend?

Or look in the status bar while hovering a page edit link, this can be quicker

diogo - resident forum ninja - strikes, once again

  • Like 2
Link to comment
Share on other sites

Or look in the status bar while hovering a page edit link, this can be quicker

diogo - resident forum ninja - strikes, once again

hint: if you know the answer, just click "Post" and then edit post ^_^ 

  • Like 2
Link to comment
Share on other sites

Hover works too, but most of the time I'm fighting with the mouse to get a tooltip ;)

/wire/modules/Process/ProcessPageList/ProcessPageList.js

function listChild(child) {
	//bla-bla-bla
	.attr('title', child.path)
	//bla-bla-bla

change to something like:

.attr('title', child.path + ' id' + child.id)

it will show ID on tooltip.

And the question =)

How made this not by hacking "core"?

Link to comment
Share on other sites

Look in the url of the browser while editting a page:

Or hover the edit link on the tree and see it on the status bar of the browser.

I'm in the interesting part of the forum. This is very useful to know and to work with.

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...