Jump to content

How to reuse renderNav() from blog.inc


totoff
 Share

Recommended Posts

Hi all,

again this a more or less PHP-related question: I'm trying to reuse renderNav from the blog.inc file as found in the blog profile. The function accepts parameters:

function renderNav($headline, $items, $currentURL = '', $mobile = true)

The comment sections says:

@param array|PageArray $items May be an array of Page objects or array of ($url => $label)

Taken as it is the function outputs the title of the page objects in $items which works fine BUT I would like to output it a different field value ($page->client instead of $page->title in my case).

This is where I am stuck with my limited PHP skills. How can I make the function output another field value than $page->title? How would I "put together" an array that contains this field values so that I can assign it as key => value pairs to $items?

Thanks

Link to comment
Share on other sites

Give me a couple of minutes...will post a solution...
 
Confirm, do you want the URL to the pages even though the 'title' will actually be the $page->client?
 
---------------------------------------------------------------------
Edit 1

Something like this should work...

$posts = $pages->find('template=post, limit=10');
$customUrls = array();

//custom array with $url => $label pairs (url= page url; and label = value of page->client [text])
foreach ($posts as $post) $customUrls[$post->url] = $post->client;//I am assuming $post->client is a text field?

echo renderNav('Custom Links', $customUrls);//set the last two parameters if you need to, i.e. $currentURL and $mobile

---------------------------------------------------------------------

Edit 2

By the way, above I assume you want to reuse renderNav() within the Blog profile itself. Remember it includes /markup/nav.php/ in line #277. If instead you want to reuse the function elsewhere without having to include nav.php, you can bring in the nav.php code physically into your (copied) renderNav() code. If this is too complicated for you, just copy the renderNav() code from MarkupBlog; it is the same code anyway :-). The Blog modules tutorials could also be handy. Here's is the renderNav() one.

Edited by kongondo
  • Like 2
Link to comment
Share on other sites

Many thanks Kongondo,

you are about to become my PHP mentor ;-)

I haven't had a chance to try this as I was offline since yesterday and will be offline again until Monday. I will try it than and report back, but it looks like the solution I was looking for.

Thanks again!

Link to comment
Share on other sites

No worries. Yes, it does work. The only thing to decide is whether you will be calling the function from blog.inc or copy and pasting its code into your own template file (for which you would also need the /markup/nav.php/ code)...Let me know how it goes...

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

×
×
  • Create New...