• Resolved mypersonalaccent

    (@mypersonalaccent)


    Hello,

    I would like to implement a line break in PHP code but I’m not sure how to do it? Specifically on my main page: http://www.mypersonalaccent.com/

    When it says By Author on November 25, 2013. I want a line break so it says:
    By Author
    on November 25, 2013

    I have found the code:

    $items .= '<div class="details-wrap">';
    $items .= '<h4><a href="'.$post_permalink.'">'.$item_title.'</a></h4>';
    $items .= '<div class="post-item-details">'. sprintf(__('By %1$s on %2$s', 'swiftframework'), $post_author, $post_date) .'</div>';

    But no matter how I edit it, I can’t seem to get it to work. I have tried adding various forms of /n and nl2br and it either produces an error, the /n prints, or nothing happens.

    Any help, please?

Viewing 3 replies - 1 through 3 (of 3 total)
  • You need an html line break, a <br> tag. Technically you should break this out into two separate sprintf()’s as well since you’re adding more html.

    $items .= '<div class="details-wrap">';
    $items .= '<h4><a href="'.$post_permalink.'">'.$item_title.'</a></h4>';
    $items .= '<div class="post-item-details">'. sprintf(__('By %1$s', 'swiftframework'), $post_author );
    $items .= '';
    $items .= sprintf(__('On %1$s', 'swiftframework'), $post_date) ).'</div>';
    Thread Starter mypersonalaccent

    (@mypersonalaccent)

    Thank you, so much Andrew! It actually did not work properly but I wouldn’t have been able to do it without you. I just had to add a br here is the code I used:

    $items .= '<div class="details-wrap">';
    $items .= '<h4><a href="'.$post_permalink.'">'.$item_title.'</a></h4>';
    $items .= '<div class="post-item-details">'. sprintf(__('By %1$s', 'swiftframework'), $post_author );
    $items .= '<br>';
    $items .= sprintf(__('On %1$s', 'swiftframework'), $post_date); '</div>';

    Just in case anyone needs it.

    Thank you!

    Oops! Accidentely removed my br tag during an edit, glad you caught it. Happy coding.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘PHP Line Break Help’ is closed to new replies.