• Resolved DeveWeb

    (@deveweb)


    hi team, well i have a problem, I not have much experience in php and I need change a code, i need change this code

    1)

    $postheader .= ‘<span class=”entry-meta”><span class=”entry-comments”>’ . get_comments_number() . ‘</span>’;

    for this code

    2)

    <span class=”entry-meta”><span class=”entry-subcat”>
    <?php
    $cats = get_the_category();
    if (count($cats) > 1) {
    echo $cats[1]->cat_name;
    } else {
    echo $cats[0]->cat_name;
    }
    ?>

    I tried to change it but I get an error, i tried to change it for this code

    3)

    $postheader .= ‘<span class=”entry-meta”><span class=”entry-subcat”>’ . $cats = get_the_category(); if (count($cats) > 1) { echo $cats[1]->cat_name; } else { echo $cats[0]->cat_name; };

    can someone help me please.!!

Viewing 6 replies - 1 through 6 (of 6 total)
  • What are you trying to do? Can you provide a link to your site?

    Thread Starter DeveWeb

    (@deveweb)

    hi thanks for you reply, I want the code number 2) modify it as number 1) I tried to do it and the result is the code number 3) I dont have active the website, I’m designing and programming on localhost 🙁

    What do you mean modify it as a number? Cast the variable as an integer?

    It looks like you’re checking the number of categories assigned to a post and if there’s more than one, display the second result, otherwise display the first result.

    Assuming you’re within the loops, this will work:

    $cats = get_the_category(get_the_ID());
    
    if(count($cats) > 1) echo $cats[1]->cat_name;
    else echo $cats[0]->cat_name;

    If you’re not, sub get_the_ID() for a $id of the post you want to check.

    Thread Starter DeveWeb

    (@deveweb)

    no dude does not work, let me explain better, sorry my English is little bad, I just want to put this code

    <?php
    $cats = get_the_category();
    if (count($cats) > 1) {
    echo $cats[1]->cat_name;
    } else {
    echo $cats[0]->cat_name;
    }
    ?>

    in the middle of this code

    $postheader .= ‘<span class=”entry-meta”><span class=”entry-subcat”>’ . #####HERE###### . ‘</span>’;

    look the code number 1)i wanna remove

    get_comments_number()

    and put it the code number 2) thanks dude

    <?php
    $cats = get_the_category(get_the_ID());
    
    if(count($cats) > 1) $pageheader = $cats[1]->cat_name;
    else $pageheader = $cats[0]->cat_name;
    
    $postheader .= '<span class="entry-meta"><span class="entry-subcat">'. $pageheader.'</span>';
    
    ?>
    Thread Starter DeveWeb

    (@deveweb)

    dudeeeee you areee the best, work perfect… really thanks a lotttt 🙂

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘I trying to modify a code.. help please’ is closed to new replies.