views:

27

answers:

2

I'm writing a sidebar for my site and I'm trying to check if:

  1. The page is a post, via: is_post()
  2. The author can edit the post via: current_user_can('edit_post')

I'm trying to combine both of these conditions, but I'm horrid at PHP and I just can't figure out the syntax to do so. I figured it'd be something like below. Could you please let me know what I'm doing wrong? I'm assuming it's something simple, but my inexperience is causing problems and I can't find the right example/documentation to help me out.

<?php if is_single and if (current_user_can('edit_post')) { ?> <li><a href="#">Edit post</a></li> <?php ;} ?>

+6  A: 

It should be:

<?php if (is_single() && current_user_can('edit_post')) { ?>
 <li><a href="#">Edit post</a></li>
<?php } ?>
Sarfraz
That was it, thank you! I knew it was a syntax problem. Learn something every day. Thanks again. I'll mark your answer as the solution as soon as it allows me to do so.
steelfrog
@steelfrog: You are welcome, thanks :)
Sarfraz
+2  A: 

The syntax and idea is:

if (true && true) { 
   // things will happen ...
}

For your functions:

if (is_single() && current_user_can('edit_post')) { ...
Māris Kiseļovs