Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Code verification

  • This topic is empty.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #36290
    fectio1
    Member

    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.

    post_content ) {
    echo "Description:";
    echo "
    ";
    echo the_content();
    } else {
    echo "Coming Soon";
    } ?>
    #95327
    jamygolden
    Member

    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:

    post_content != '' ) {

    Otherwise it would be:

    post_content ) {
    #95328
    fectio1
    Member

    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!

    #95329
    jamygolden
    Member

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

    post_content != '' ) {
    echo "Description:";
    the_content();
    } else {
    echo "Coming Soon";
    } ?>
    #95331
    fectio1
    Member

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

    #95332
    fectio1
    Member

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

    post_content )
    post_content != '' )
    #95334
    jamygolden
    Member
    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.

    #95335
    fectio1
    Member

    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)
  • The forum ‘Back End’ is closed to new topics and replies.