Jump to content

Recommended Posts

Posted

What is the best way to add an image to one of my navigation links? I would like to add an image tag right before my homepage link, within the anchor tags.

Starting from the default navigation code:

$homepage = $pages->get("/");
					$children = $homepage->children;
					$children->prepend($homepage);

					foreach($children as $child) {
						$class = $child === $page->rootParent ? " class='on'" : '';
						echo "<li><a$class href='{$child->url}'>{$child->title}</a></li>";
					}

I tried editing the $homepage variable to concatenate an image tag before $pages->get("/"); but that threw an error since (I'm guessing) the prepend() method is specific about the kind of input it will take in its parameter.

I'm probably going about this all wrong. Any help would be greatly appreciated.

Posted

When you are dealing with API functions, you aren't dealing with markup. You are only dealing with markup when you create and output it yourself. I think this may be what you are looking for?

// .. starting in the middle of your example: 
foreach($children as $child) {
   $class = $child->id == $page->rootParent->id ? " class='on'" : '';
   echo "<li><a$class href='{$child->url}'>";
   if($child->id == $homepage->id) echo "<img src='your image file' />";
   echo $child->title . "</a></li>";
}

  • Like 1

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
×
×
  • Create New...