• Resolved roger riesbeck

    (@roger-riesbeck)


    it is this line that started the … $output .= ‘<a href
    sublime text shows the error and when I inspect the web browser, it is precisely this line is wrong? but I can not see the error!
    <?php
    $categories = get_the_category( );
    $separator = “, “;
    $output = ”;
    if ($categories){
    foreach ($categories as $category ) {
    $output .= ‘term_id) . ‘”>’ . $category->cat_name . ‘‘ . $separator;
    }
    echo trim($output, $separator);
    }

    ?>

Viewing 6 replies - 1 through 6 (of 6 total)
  • michal.lausch

    (@michallausch)

    Hi,

    Can You please paste that code again putting it in backticks?
    Right now it’s a little bit messy here.

    Greetings
    M

    Thread Starter roger riesbeck

    (@roger-riesbeck)

    Thread Starter roger riesbeck

    (@roger-riesbeck)

    Sorry it my first time to post and I don′t get it right…here is a link to the code.
    https://stackoverflow.com/questions/33826588/wordpress-php-and-html

    michal.lausch

    (@michallausch)

    Hi,

    Well, the piece of code in question is:

    <?php
            $categories = get_the_category( );
            $separator = ", ";
            $output = '';
    
            if ($categories){
                foreach ($categories as $category ) {
                 $output .= '<a href="' . get_the_category_link($category->term_id) . '">' . $category->cat_name . '</a>' . $separator;
                }
                echo trim($output, $separator);
            }
    ?>

    Have You tried to use :
    get_category_link($category->term_id)
    instead of:
    get_the_category_link($category->term_id)
    ?

    Greetings
    M

    Thread Starter roger riesbeck

    (@roger-riesbeck)

    Finally …. big thanks for your help !!! what is the difference between . get_category_link and. get_the_category_link?

    michal.lausch

    (@michallausch)

    Well…

    Main difference is that get_category_link exists and get_the_category_link do not.

    I do that same mistake at least once a month:)

    Greetings
    M

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Need help to solve a code problem’ is closed to new replies.