- This topic is empty.
-
AuthorPosts
-
January 24, 2012 at 11:50 am #36290fectio1Member
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";
} ?>January 24, 2012 at 1:09 pm #95327jamygoldenMemberI 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 ) {
January 24, 2012 at 1:15 pm #95328fectio1MemberIt 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 #95329jamygoldenMemberIf 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";
} ?>January 24, 2012 at 1:26 pm #95331fectio1MemberAwesome! Thanks so much for the help. Sincerely appreciated.
January 24, 2012 at 1:41 pm #95332fectio1MemberIf you dont mind? What is the difference between besides $content being a variable.
post_content )
post_content != '' )
January 24, 2012 at 1:47 pm #95334jamygoldenMemberif($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 #95335fectio1MemberThanks a lot for explaining it. It worked both ways. So I am assuming the !=” is saying this is empty. I have been schooled :)
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.