Topic: Specify specific pages for menu

Hi!  I have another question smile

I am creating a main navigation bar and I would like to restrict the links to specific pages.  I was thinking I could use something like this:

from _http://www.wolfcms.org/wiki/navbook:leave-out

<ul>
<li<?php echo url_match('/') ? ' id="current"': null; ?>><a href="<?php echo URL_PUBLIC; ?>">Home</a></li>
<?php foreach($this->find('/')->children() as $menu): ?>
<?php
$omit_pages = array('somepageslug', 'someotherpageslug');
if (in_array($menu->slug, $omit_pages)) {
    continue;
}
?>
<li<?php echo (url_start_with($menu->url)) ? ' id="current"': null; ?>>
<?php echo $menu->link() . PHP_EOL; ?></li>
<?php endforeach; ?>
</ul>

but I would like to change $omit_pages to $include_pages.  Is there a way to do this with existing functions?

Thanks!

Also, shouldn't

$omit_pages = array('somepageslug', 'someotherpageslug');
if (in_array($menu->slug, $omit_pages)) {
    continue;
}

be

$omit_pages = array(somepageid, someotherpageid);
if (in_array($menu->id, $omit_pages)) {
    continue;
}

?  In case the page slug changes?

Thumbs up

Re: Specify specific pages for menu

Similarly, if the find() function searched by id as well as by slug/uri, several of these steps:

One of Wolf’s core plugins is the “Archive” feature which allows Wolf CMS to be used for “blogging”, or other dynamic “news” type content.

By default, when Wolf is installed, this is already set up for the user. There are two articles already created under the “Articles” page. Some users might want to call this “News” or “Blog” or some other name, however.

To change this page’s title in the default Wolf installation, follow these four steps. (These instructions use the new name “News”, but you can obviously change this to whatever you want!)

Open the “Articles” page and change the name of the page to “News”.
Click on its sidebar tab, change <?php $article = $this->find('articles'); ?> to <?php $article = $this->find('news'); ?>. Save.
Open Homepage; in line 1 change $this->find('/articles/') to $this->find('/news/').
Click on its sidebar tab, under the “Recent Entries” heading (h3), the next line is <?php $page_article = $this->find('/articles/'); ?>; change it to <?php $page_article = $this->find('/news/'); ?>. Save.
Don

from _http://www.wolfcms.org/wiki/howto:change_the_title_of_articles

would be unnecessary.

I guess I should right a find_by_id() helper function! I will let everyone know how that goes.

Thumbs up

Re: Specify specific pages for menu

I looked in Layout.php from the wolf/app/models directory and found the find function, and a findById function as well!

So I changed the functions on the homepage and in the Articles/News section to findById, so now when if I change the title of Articles->News->Whatever, I won't have to worry about changing the functions as well.

Thumbs up

Re: Specify specific pages for menu

Hey there jameslove... just catching this one... take a look here: http://www.wolfcms.org/phpdoc/wolf/models/Page.html

You'll see there's a Page::findById() method already available. smile Look through the Page class for more goodies.

Wolf CMS founder and lead developer
Please always check the Support forums and Wiki before asking. (My Ohloh account.)
Like Wolf CMS? Consider making a financial contribution.

5

Re: Specify specific pages for menu

jameslov wrote:

So I changed the functions on the homepage and in the Articles/News section to findById, so now when if I change the title of Articles->News->Whatever, I won't have to worry about changing the functions as well.

Great idea, James! The linkById() function is quite new, but it would be good to change the default layouts over to that for the Articles page, just because this is a prime candidate for re-naming, and it would save hassles for new users.

Btw, browsing the functions and constants list might be another good idea before you set out to write something -- it might already be written!

Of course, if it isn't ... do get stuck in! wink

Re: Specify specific pages for menu

Thank you for the quick replies gentlemen, very helpful stuff!

Thanks for pointing out the linkById() function, that will be very helpful!

James

Thumbs up