php within echo statement / hide element / php else statement

Thread Solved

Join Date: May 2009
Posts: 20
Reputation: cjay175 is an unknown quantity at this point 
Solved Threads: 0
cjay175 cjay175 is offline Offline
Newbie Poster

php within echo statement / hide element / php else statement

 
0
  #1
Jul 2nd, 2009
hi all,

I am wondering if someone could give me a quick hand with some php im trying to edit in Wordpress.

Heres the original peice I am trying to edit:
  1. <div class='dateauthor'>
  2. <small class='capsule'><?php the_time('F jS, Y') ?> by <?php the_author() ?>
  3. </small>
  4. </div>

What I want to do is when "the_author" equals "admin" for the div to be hidden or deleted.

I have added this to make sure that it can find admin
  1. <?php if ($author=="admin"){echo "hello24241";} ?>
and edit here...
  1. <?php $author=the_author() ?>


My question I guess would be is there a statement that would be able to hide/delete the div? Or should I be re-writing this code, like this...

<?php $author = the_author(); ?>
<?PHP if ($author=="admin")?> working
<?php else: ?> \* I get an error on this line *\
        <div class='dateauthor'>
            <small class='capsule'><?php the_time('F jS, Y') ?> by <?php the_author() ?> 
			</small>
        </div>
<?php endif; ?>


Thanks for any help,

and if you need me to be a little more clear just ask,

tian
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 197
Reputation: FlashCreations is an unknown quantity at this point 
Solved Threads: 17
FlashCreations's Avatar
FlashCreations FlashCreations is offline Offline
Junior Poster

Re: php within echo statement / hide element / php else statement

 
0
  #2
Jul 2nd, 2009
If you use wp_list_authors(); it should by default exclude the admin account. If not you could try:
  1. Posted By: <?php wp_list_authors('exclude_admin=true&hide_empty=true'); ?>

See The Codex Page for wp_list_authors() and The Codex Page on Author Templates for more.
Last edited by FlashCreations; Jul 2nd, 2009 at 11:16 pm.
FlashCreations
(aka PhpMyCoder)

About Me | My Blog | Contact Me
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 15
Reputation: bgeisel1 is an unknown quantity at this point 
Solved Threads: 2
bgeisel1 bgeisel1 is offline Offline
Newbie Poster

Re: php within echo statement / hide element / php else statement

 
0
  #3
Jul 2nd, 2009
It depends on what you're trying to do. If you want that div to never show up, then you can do something like:

  1. <?php if (!$author == "admin") { ?>
  2. <div class='dateauthor'>
  3. ...
  4. </div>
  5. <?php } ?>
No need to have the else clause when you aren't really using the if. BTW, I believe you want:
  1. <?php $author = get_the_author(); ?>
else it will just print the author each time you call the_author();

Also, if you want to hide the div, you can just add some CSS and set the class or manually insert style="" to set "display:none;" when your php deems it appropriate.

That help?

-geis
Some Favorite Sites -- favorite b/c they're mine :-)
Buy Linux Backup Software - InternetStarting, Websites for Beginners
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 20
Reputation: cjay175 is an unknown quantity at this point 
Solved Threads: 0
cjay175 cjay175 is offline Offline
Newbie Poster

Re: php within echo statement / hide element / php else statement

 
0
  #4
Jul 3rd, 2009
Hey thanks a lot for the replies,

Flash, with the wp_list that is used for the page that displays the authors. I want to hide the info on the actual post/page that is view where it has the author beside the article (but I want to display anybody else besides admin). I have tried the could you suggested in the author_template but won't work. I am assuming this is just for just the author listing page, thanks.


bgeisel:

I might be missing something here, but I want to normally display the following html (this is what is there now):
  1. <div class='dateauthor'>
  2. <small class='capsule'><?php the_time('F jS, Y') ?> by <?php the_author() ?>
  3. </small>
  4. </div>

But when the author is an admin for the div to be hidden.

I tried this from your code:
  1. <div class='dateauthor'>
  2. <small class='capsule'><?php the_time('F jS, Y') ?> by <?php $author = the_author() ?>
  3. </small>
  4. </div>
  5.  
  6. <?php if ($author == "admin") { ?>
  7. <div class='dateauthor'>
  8. ...
  9. </div>
  10. <?php } ?>
But it just creates another div as expected with the periods.

Sorry but thank you for the help
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 15
Reputation: bgeisel1 is an unknown quantity at this point 
Solved Threads: 2
bgeisel1 bgeisel1 is offline Offline
Newbie Poster

Re: php within echo statement / hide element / php else statement

 
0
  #5
Jul 3rd, 2009
Originally Posted by cjay175 View Post
bgeisel:

I might be missing something here, but I want to normally display the following html (this is what is there now):
  1. <div class='dateauthor'>
  2. <small class='capsule'><?php the_time('F jS, Y') ?> by <?php the_author() ?>
  3. </small>
  4. </div>

But when the author is an admin for the div to be hidden.

I tried this from your code:
  1. <div class='dateauthor'>
  2. <small class='capsule'><?php the_time('F jS, Y') ?> by <?php $author = the_author() ?>
  3. </small>
  4. </div>
  5.  
  6. <?php if ($author == "admin") { ?>
  7. <div class='dateauthor'>
  8. ...
  9. </div>
  10. <?php } ?>
But it just creates another div as expected with the periods.

Sorry but thank you for the help
Hey cjay,

You're supposed to replace your code with what I provided. The 3 dots are an ellipsis and it means that something is being omitted. In this case you were supposed to put the rest of your HTML in there ;-)

The `if ($admin != get_the_author())` should only display the <div> ... </div> when the author is not equal to admin. (where "..." is whatever is inside the div.)

I think that makes the whole thing look something like this:

  1. <?php
  2. $author = get_the_author();
  3. if ($author != "admin") {
  4. // Only display this div if our author is not "admin"
  5. ?>
  6. <div class='dateauthor'>
  7. <small class='capsule'><?php the_time('F jS, Y') ?> by <?php the_author() ?>
  8. </small>
  9. </div>
  10. <?php } ?>

Little better?

-geis
Some Favorite Sites -- favorite b/c they're mine :-)
Buy Linux Backup Software - InternetStarting, Websites for Beginners
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 197
Reputation: FlashCreations is an unknown quantity at this point 
Solved Threads: 17
FlashCreations's Avatar
FlashCreations FlashCreations is offline Offline
Junior Poster

Re: php within echo statement / hide element / php else statement

 
0
  #6
Jul 3rd, 2009
Ok I didn't realize that...whoops! Anyway I believe bgeisel meant for you to get the author name first and replace the ... with the_author(). So something like this:
  1. <?php
  2. if (!get_the_author()=="admin")
  3. {
  4. echo " <div class='dateauthor'>";
  5. echo " <small class='capsule'>".the_time('F jS, Y')." by ".the_author();
  6. echo " </small>";
  7. echo " </div>";
  8. }
  9. ?>
FlashCreations
(aka PhpMyCoder)

About Me | My Blog | Contact Me
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 20
Reputation: cjay175 is an unknown quantity at this point 
Solved Threads: 0
cjay175 cjay175 is offline Offline
Newbie Poster

Re: php within echo statement / hide element / php else statement

 
0
  #7
Jul 3rd, 2009
Ahh... lol

Opps, I didn't realize that I thought it was odd "..." my bad, but now I know.

Anywayz I put your code in and it worked wonderfully.

Thanks a lot flash and bgeisel
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 657 | Replies: 6
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC