Grow your CSS skills. Land your dream job.

Code verification

  • # January 24, 2012 at 11:50 am

    I want to display the content if it is available and if not display “coming soon”

    Is this right? It works, I just want to make sure it is the correct way and most efficient way.

    < ?php if($content = $post->post_content ) {
    echo "Description:";
    echo "
    ";
    echo the_content();
    } else {
    echo "Coming Soon";
    } ?>
    # January 24, 2012 at 1:09 pm

    I think you’re statement will always be true since you’re declaring a variable within that if. 1 = is declaration, two is equal to.

    Also, you need to see what $post->post_content would look like if it was empty, is it an empty string?

    If it’s an empty string the statement would start with:

    < ?php if($post->post_content != '' ) {

    Otherwise it would be:

    < ?php if($post->post_content ) {
    # January 24, 2012 at 1:15 pm

    It is an empty string. Basically I want to get

    the_content

    if any content exist. If it does not, I want to get “Coming Soon”

    I was just making sure it was clean or if there was a better way. Thanks!

    # January 24, 2012 at 1:20 pm

    If the_content() doesn’t exist and it returns an empty string, you should have this:

    < ?php if($post->post_content != '' ) {
    echo "Description:";
    the_content();
    } else {
    echo "Coming Soon";
    } ?>
    # January 24, 2012 at 1:26 pm

    Awesome! Thanks so much for the help. Sincerely appreciated.

    # January 24, 2012 at 1:41 pm

    If you dont mind? What is the difference between besides $content being a variable.

    < ?php if($content = $post->post_content )
    < ?php if($post->post_content != '' )
    # January 24, 2012 at 1:47 pm
    if($content = $post->post_content )

    will always be true. You are defining a variable.

    $a = 10;
    $b = 20;

    if ( $a = $b ) {
    echo 'true';
    } else {
    echo 'false';
    }

    You will get true every time, because you are setting the variable, not asking if $a is equal to $b. You are saying $a IS $b, and it goes ‘well, that’s true’.

    As for the != ” thing, I’m not 100% sure if php sees an empty string as truey or not (I’m more of a js guy, but php and js are basically the same). Now that I think about it, it probably doesn’t, so you could just go:

    if($post->post_content)

    but just be sure to check that it gives you the result you want.

    # January 24, 2012 at 1:56 pm

    Thanks a lot for explaining it. It worked both ways. So I am assuming the !=” is saying this is empty. I have been schooled :)

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".