steelfrog
steelfrog

Reputation: 131

Wordpress two conditions (and if)

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 ;} ?>

Upvotes: 1

Views: 2671

Answers (2)

Māris Kiseļovs
Māris Kiseļovs

Reputation: 17295

The syntax and idea is:

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

For your functions:

if (is_single() && current_user_can('edit_post')) { ...

Upvotes: 2

Sarfraz
Sarfraz

Reputation: 382826

It should be:

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

Upvotes: 8

Related Questions