WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] A simple question on php - category slug (3 posts)

  1. oldmankit
    Member
    Posted 3 years ago #

    Hi,

    I've been working all day to try and do something very simple but can't. I'm sure someone will be able to help me in no time.

    I'm using thematic and am creating a custom post title. I want to create a new div class which has got the category slug in it.

    ...
    $posttitle .= '<div class="icon-';
    //I want to insert the category slug here
    $posttitle .= '">a css background image will go here</div>';

    From this page I found what I wanted. However, when I do:

    $category =  get_the_category();
    echo $category[0]->category_nicename;

    then it displays the slug outsite of my posttitle. But if I do:

    ...
    $posttitle .= '<div class="icon-';
    $category =  get_the_category();
    $posttitle .= echo $category[0]->category_nicename;
    $posttitle .= '">a css background image will go here</div>';

    Then it gives me an error:

    Parse error: syntax error, unexpected T_ECHO in /home/peaceand/public_html/blog/wp-content/themes/custom/functions.php on line 39

  2. alchymyth
    Forum Moderator
    Posted 3 years ago #

    just remove the 'echo' - you are working with string concatenation, and using the echo is wrong in this situation.

  3. oldmankit
    Member
    Posted 3 years ago #

    just remove the 'echo' - you are working with string concatenation, and using the echo is wrong in this situation.

    That's great. I can't believe I didn't try that. Thank you very much.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags