943,829 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 1649
  • PHP RSS
Jul 2nd, 2009
0

php within echo statement / hide element / php else statement

Expand Post »
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:
PHP Syntax (Toggle Plain Text)
  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
PHP Syntax (Toggle Plain Text)
  1. <?php if ($author=="admin"){echo "hello24241";} ?>
and edit here...
PHP Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 10
Solved Threads: 2
Light Poster
cjay175 is offline Offline
49 posts
since May 2009
Jul 2nd, 2009
0

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

If you use wp_list_authors(); it should by default exclude the admin account. If not you could try:
PHP Syntax (Toggle Plain Text)
  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.
Reputation Points: 47
Solved Threads: 47
Posting Whiz
FlashCreations is offline Offline
393 posts
since Sep 2008
Jul 2nd, 2009
0

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

It depends on what you're trying to do. If you want that div to never show up, then you can do something like:

php Syntax (Toggle Plain Text)
  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:
php Syntax (Toggle Plain Text)
  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
Reputation Points: 20
Solved Threads: 2
Newbie Poster
bgeisel1 is offline Offline
15 posts
since Mar 2009
Jul 3rd, 2009
0

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

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):
PHP Syntax (Toggle Plain Text)
  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:
PHP Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 2
Light Poster
cjay175 is offline Offline
49 posts
since May 2009
Jul 3rd, 2009
0

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

Click to Expand / Collapse  Quote originally posted by cjay175 ...
bgeisel:

I might be missing something here, but I want to normally display the following html (this is what is there now):
PHP Syntax (Toggle Plain Text)
  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:
PHP Syntax (Toggle Plain Text)
  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:

php Syntax (Toggle Plain Text)
  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
Reputation Points: 20
Solved Threads: 2
Newbie Poster
bgeisel1 is offline Offline
15 posts
since Mar 2009
Jul 3rd, 2009
0

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

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:
PHP Syntax (Toggle Plain Text)
  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. ?>
Reputation Points: 47
Solved Threads: 47
Posting Whiz
FlashCreations is offline Offline
393 posts
since Sep 2008
Jul 3rd, 2009
0

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

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
Reputation Points: 10
Solved Threads: 2
Light Poster
cjay175 is offline Offline
49 posts
since May 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: urgent ffmpeg help pls!!!!
Next Thread in PHP Forum Timeline: make <br> with a 'enter' key





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC