Jump to content

Include a css class in an echo


xmaverick56
 Share

Recommended Posts

So this is probably an incredibly simple thing to do, but humor me:

I'm using the following to create the navigation for my site in the header.inc:

<?php
        $root = $pages->get("/");
        $children = $root->children();
        $children->prepend($root);
        foreach($children as $child) {
        echo "<li><a href='{$child->url}'>{$child->title}</a></li>";
        }
?>
 
And it works just fine. My total noob hang-up is that I want the <li> markup to be <li class="col"> so that my CSS styles are applied to it. How do I make that happen? 
 
Thanks in advance!
Link to comment
Share on other sites

I assume you are having issues with quote matching?

You can take a couple of different approaches:

echo "<li class='col'><a href='{$child->url}'>{$child->title}</a></li>";

echo '<li class="col"><a href="'.$child->url.'">'.$child->title.'</a></li>';

Have a read through some of these links:

http://www.scriptingok.com/tutorial/Single-quotes-vs-double-quotes-in-PHP

http://www.trans4mind.com/personal_development/phpTutorial/quotes.htm

http://techtalk.virendrachandak.com/php-double-quotes-vs-single-quotes/

  • Like 3
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...