| | |
php within echo statement / hide element / php else statement
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved
![]() |
•
•
Join Date: May 2009
Posts: 20
Reputation:
Solved Threads: 0
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:
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
and edit here...
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...
Thanks for any help,
and if you need me to be a little more clear just ask,
tian
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)
<div class='dateauthor'> <small class='capsule'><?php the_time('F jS, Y') ?> by <?php the_author() ?> </small> </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)
<?php if ($author=="admin"){echo "hello24241";} ?>
PHP Syntax (Toggle Plain Text)
<?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
If you use
See The Codex Page for wp_list_authors() and The Codex Page on Author Templates for more.
wp_list_authors(); it should by default exclude the admin account. If not you could try: PHP Syntax (Toggle Plain Text)
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.
•
•
Join Date: Mar 2009
Posts: 15
Reputation:
Solved Threads: 2
It depends on what you're trying to do. If you want that div to never show up, then you can do something like:
No need to have the else clause when you aren't really using the if. BTW, I believe you want:
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
php Syntax (Toggle Plain Text)
<?php if (!$author == "admin") { ?> <div class='dateauthor'> ... </div> <?php } ?>
php Syntax (Toggle Plain Text)
<?php $author = get_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
Buy Linux Backup Software - InternetStarting, Websites for Beginners
•
•
Join Date: May 2009
Posts: 20
Reputation:
Solved Threads: 0
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):
But when the author is an admin for the div to be hidden.
I tried this from your code:
But it just creates another div as expected with the periods.
Sorry but thank you for the help
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)
<div class='dateauthor'> <small class='capsule'><?php the_time('F jS, Y') ?> by <?php the_author() ?> </small> </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)
<div class='dateauthor'> <small class='capsule'><?php the_time('F jS, Y') ?> by <?php $author = the_author() ?> </small> </div> <?php if ($author == "admin") { ?> <div class='dateauthor'> ... </div> <?php } ?>
Sorry but thank you for the help
•
•
Join Date: Mar 2009
Posts: 15
Reputation:
Solved Threads: 2
•
•
•
•
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)
<div class='dateauthor'> <small class='capsule'><?php the_time('F jS, Y') ?> by <?php the_author() ?> </small> </div>
But when the author is an admin for the div to be hidden.
I tried this from your code:
But it just creates another div as expected with the periods.PHP Syntax (Toggle Plain Text)
<div class='dateauthor'> <small class='capsule'><?php the_time('F jS, Y') ?> by <?php $author = the_author() ?> </small> </div> <?php if ($author == "admin") { ?> <div class='dateauthor'> ... </div> <?php } ?>
Sorry but thank you for the help
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)
<?php $author = get_the_author(); if ($author != "admin") { // Only display this div if our author is not "admin" ?> <div class='dateauthor'> <small class='capsule'><?php the_time('F jS, Y') ?> by <?php the_author() ?> </small> </div> <?php } ?>
Little better?
-geis
Some Favorite Sites -- favorite b/c they're mine :-)
Buy Linux Backup Software - InternetStarting, Websites for Beginners
Buy Linux Backup Software - InternetStarting, Websites for Beginners
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)
<?php if (!get_the_author()=="admin") { echo " <div class='dateauthor'>"; echo " <small class='capsule'>".the_time('F jS, Y')." by ".the_author(); echo " </small>"; echo " </div>"; } ?>
![]() |
Similar Threads
- passing parameters in ajax through php echo command (JavaScript / DHTML / AJAX)
- Problems with PHP and CSS in IE 6.0 (PHP)
- HTML codes in PHP (PHP)
- show/hide element by name (JavaScript / DHTML / AJAX)
- Open In New Window Php (PHP)
- How to insert PHP in HTML language? (PHP)
- mysql errors, from submit.php and index.php (PHP)
- PHP question regarding Forms (PHP)
- PHP Parse error: parse error, unexpected T_STRING (PHP)
Other Threads in the PHP Forum
- Previous Thread: urgent ffmpeg help pls!!!!
- Next Thread: make <br> with a 'enter' key
| Thread Tools | Search this Thread |
apache api array basic beginner binary body broken cakephp class cms code computing confirm cron curl customizableitems database date date/time delete display dynamic echo email error file files filter folder form forms forum function functions gc_maxlifetime global google header headmethod howtowriteathesis href htaccess html iframe image include ip javascript joomla limit link list login malfunction memmory memory menu mlm msqli_multi_query multiple mycodeisbad mysql navigation oop parameter parsing paypal pdf php query question random recourse recursion regex script search seo server sessions snippet source space sql static system table thesishelp trouble tutorial update upload url variable video web webdesign xml youtube





