Old Pink Posted December 11, 2006 Share Posted December 11, 2006 Hi there,Wasted the last hour of my life trying to get this to work, no matter what I try it fails.Anyway, here's the scenario. My wordpress blog theme has a function that when a person who has commented on my site before leaves a comment, it says "Welcome back $comment_author"This is terrible, cookies don't last long enough and people don't see the message. I want it to say "Welcome back $user_identity" and if there's no user identity present, "Welcome back $comment_author" and then if there's no $comment_author present, "Welcome visitor."Sounds simple? It's not. Here's the code that's there all ready, the code I want modified:[code]<?php if( '' !== $comment_author ) { ?><p>Welcome back <b><?php echo $comment_author; ?></b><?php } ?>[/code]I can get it to say "Welcome back $user_identity" easy enough, but I want the system to LOOK for $user_identity, then if it's not found look for $comment_author then if that's not found user "visitor"It sounds simple but when trying to use numerous elses and ifs the page simply breaks. This is soo annoying. I mean, I can even get it to check for one then use "visitor" but I simply can't make it check for one, then another, then visitor. The above code is [i]all[/i] you need to provide, the $user_identity etc. are already provided, you don't need to create a code to find them, if you know what I mean.[b]EDIT:[/b] I will make a post on my blog advertising your site if you help me with this!! Quote Link to comment https://forums.phpfreaks.com/topic/30275-hello-user_identitycomment_authorvisitor/ Share on other sites More sharing options...
Old Pink Posted December 11, 2006 Author Share Posted December 11, 2006 Snippet updated, mistake removed.Added information: If you are the person which fixes this, I will make an post on my forum advertising the site of your choice.Come on, this must be easy, numerous elses/ifs?!?Link to site in question: http://www.mbhoy.com (feel free to remove if in violation of tos) Quote Link to comment https://forums.phpfreaks.com/topic/30275-hello-user_identitycomment_authorvisitor/#findComment-139271 Share on other sites More sharing options...
Old Pink Posted December 11, 2006 Author Share Posted December 11, 2006 Tried the logical:[code]<?phpif( '' !== $user_identity ) { echo "back <b>$user_identity</b>.</p>"; } elseif( '' !== $comment_author ) { echo "back <b>$comment_author</b>.</p>";} else {echo "visitor.</p>"} ?>[/code] and the page breaks. Quote Link to comment https://forums.phpfreaks.com/topic/30275-hello-user_identitycomment_authorvisitor/#findComment-139276 Share on other sites More sharing options...
craygo Posted December 11, 2006 Share Posted December 11, 2006 Where would the $user information come from?Where is $comment_user coming from??Not sure where these are coming from but try this out[code]<?phpif(isset($user_identity)){$visitor = $user_identity;} else { if(isset($comment_author)){ $visitor = $comment_author; } else { $visitor = "visitor"; }}echo "Welcome Back $visitor";?>[/code]RayWithout anything to search on your will not have much luck.Ray Quote Link to comment https://forums.phpfreaks.com/topic/30275-hello-user_identitycomment_authorvisitor/#findComment-139278 Share on other sites More sharing options...
Old Pink Posted December 11, 2006 Author Share Posted December 11, 2006 Trust me, they're coming from somewhere in wordpress, when echoing randomly they come out fine, it's the whole else/elseif/if thing that seems to be failing on me. [code]<?php if ( '' !== $user_identity ) : ?><?php echo $user_identity; ?><?php elseif ( '' !== $comment_author ) : ?> <?php echo $comment_author; ?><?php else : ?><?php echo "visitor."; ?>[/code]^^ fails too!And when I say fails, I mean the page completely breaks and looks horrible. Quote Link to comment https://forums.phpfreaks.com/topic/30275-hello-user_identitycomment_authorvisitor/#findComment-139279 Share on other sites More sharing options...
Old Pink Posted December 11, 2006 Author Share Posted December 11, 2006 craygo, it seems your code has worked! :D Wait while I test it further... Quote Link to comment https://forums.phpfreaks.com/topic/30275-hello-user_identitycomment_authorvisitor/#findComment-139280 Share on other sites More sharing options...
Old Pink Posted December 11, 2006 Author Share Posted December 11, 2006 craygo, your code works well, except when "Welcome visitor" is supposed to be displayed, it simply says "Welcome back"I'll have a fiddle. :P Quote Link to comment https://forums.phpfreaks.com/topic/30275-hello-user_identitycomment_authorvisitor/#findComment-139283 Share on other sites More sharing options...
Old Pink Posted December 11, 2006 Author Share Posted December 11, 2006 Fiddle failed, any insight, craygo? Quote Link to comment https://forums.phpfreaks.com/topic/30275-hello-user_identitycomment_authorvisitor/#findComment-139285 Share on other sites More sharing options...
freeloader Posted December 11, 2006 Share Posted December 11, 2006 [code]<?phpif(isset($user_identity)){$visitor = $user_identity;} else { if(isset($comment_author)){ $visitor = $comment_author; } else { $visitor = "visitor"; }} ?><p>Welcome back <b><?php echo $visitor;?></b>[/code]^^ that's to be compatible with your earlier mentioned lay-out.The visitor problem is probably because craygo's script just checks is the variable $comment_author or $user_identity [b]exist[/b]. It's possible that they're created but not filled in. If you want us to make a compatible script, you need to provide where those variables are coming from and what creates them based on which parameters.You could try something like this:[code]<?phpif(isset($user_identity)){if($user_identity == ""){$visitor = "visitor";}else{$visitor = $user_identity;}} else { if(isset($comment_author)){if($comment_author == ""){$visitor = "visitor";}else{$visitor = $comment_author;} } else { $visitor = "visitor"; }} ?><p>Welcome back <b><?php echo $visitor;?></b>[/code]Don't you just love if-then clauses :DNo guaranteed success :p Quote Link to comment https://forums.phpfreaks.com/topic/30275-hello-user_identitycomment_authorvisitor/#findComment-139292 Share on other sites More sharing options...
Old Pink Posted December 11, 2006 Author Share Posted December 11, 2006 (edited) [quote author=freeloader link=topic=118228.msg482950#msg482950 date=1165874817] The visitor problem is probably because craygo's script just checks is the variable $comment_author or $user_identity exist. It's possible that they're created but not filled in. If you want us to make a compatible script, you need to provide where those variables are coming from and what creates them based on which parameters.[/quote] Yeah, you got it just as I did. Final code was: [code]<?php if(isset($user_identity)){ $visitor = $user_identity; echo "Welcome Back, <b>$visitor</b>"; } else { if( '' !== $comment_author ){ $visitor = $comment_author; echo "Welcome Back <b>$visitor</b>"; } } ?>[/code] Which displays no welcome to first time visitors, only to people who have registered/commented beforehand. Thanks all, if you'd like to contact me with links I'll link to you in a post on my blog as a reward. Edited May 4, 2022 by requinix removing email address by request Quote Link to comment https://forums.phpfreaks.com/topic/30275-hello-user_identitycomment_authorvisitor/#findComment-139293 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.