WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] problem with : echo (10 posts)

  1. taghaboy
    Member
    Posted 5 years ago #

    hi
    i have always problems with "echo", this time i add the tag:
    <?php bloginfo('stylesheet_directory'); ?>/cat-banner/
    and the script dont work, error message :
    Parse error: syntax error, unexpected T_STRING, expecting ',' or ';'

    <?php
    foreach((get_the_category()) as $category) {
    echo '<?php bloginfo('stylesheet_directory'); ?>/cat-banner/' . $category->cat_name . '.jpg" alt="' . $category->cat_name . '" />';
    }
    ?>

    Thanks for help.

  2. iridiax
    Member
    Posted 5 years ago #

    You have incorrectly nested php tags. De-nest bloginfo. Oh, and don't echo bloginfo.

  3. taghaboy
    Member
    Posted 5 years ago #

    sorry, but i don't understand you, can you pls provide an example.
    thanks

  4. iridiax
    Member
    Posted 5 years ago #

    Nesting is one tag inside another: <?php <?php ?> ?>

  5. taghaboy
    Member
    Posted 5 years ago #

    Thanks iridiax for reply,
    i try to do some change, but i'm really not a pro in php, but even if i try:

    <?php
    foreach((get_the_category()) as $category) {
    echo 'bloginfo("stylesheet_directory");/cat-banner/' . $category->cat_name . '.jpg" alt="' . $category->cat_name . '" />';
    }
    ?>

    and steel not work, thanks for help.

  6. taghaboy
    Member
    Posted 5 years ago #

    i need some help please.

  7. iridiax
    Member
    Posted 5 years ago #

  8. taghaboy
    Member
    Posted 5 years ago #

    can you please to correct for me the PHP syntax, i'will be so happy if you do.

  9. karl19
    Member
    Posted 5 years ago #

    You've probably figured this out by now, but since I came past this post when I was searching for the same thing, here's what you could do.

    Rather than using bloginfo, use get_bloginfo. Then you can use something like:

    <?php echo 'Your Blog Tagline is: ' . get_bloginfo ( 'description' ); ?>

    I guess your code would then look like this:

    <?php
    foreach((get_the_category()) as $category) {
    echo get_bloginfo ( 'stylesheet_directory' ) . '/cat-banner/' . $category->cat_name . '.jpg" alt="' . $category->cat_name . '" />';
    }
    ?>

    Note that stylesheet_directory is deprecated, so either use stylesheet_url to get to the main style.css, or template_directory if you want to get to the theme directory.

    More info under codex.wordpress.org/Template_Tags/get_bloginfo

  10. taghaboy
    Member
    Posted 5 years ago #

    Hi karl19,
    Thanks a lot for your help, the code work perfectly.
    thanks again

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags