/    Sign up×
Community /Pin to ProfileBookmark

Using PHP inside statement

Can someone please tell me the proper way of doing this. I don’t think I am supposed to be using echo but I am trying to run an if statement inside an if statement. Please help. Thanks!

[code=php]
<?php if (is_user_logged_in() && current_user_can(“access_s2member_level2”))
{ echo “<?php if(function_exists(‘wp_page_numbers’)) : wp_page_numbers(); endif; ?>”; }

else { echo ‘<a href=”/”><div class=”show-more-bar”>Show more videos</div></a>’; }
?>[/code]

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@Master00authorJun 13.2011 — Tried something like this but I get a syntax error.

[code=php]<?php
if (is_user_logged_in() && current_user_can("access_s2member_level2"))
{

if(function_exists('wp_page_numbers')) : wp_page_numbers();
}
else { echo '<a href="/"><div class="show-more-bar">Show more videos</div></a>'; }
?>[/code]
Copy linkTweet thisAlerts:
@NogDogJun 14.2011 — [code=php]
<?php
if (is_user_logged_in() && current_user_can("access_s2member_level2")) {
if (function_exists('wp_page_numbers')) {
wp_page_numbers();
}
} else {
echo '<a href="/"><div class="show-more-bar">Show more videos</div></a>';
}
?>
[/code]

Or if you prefer the if():endif syntax (I don't):
[code=php]
<?php
if (is_user_logged_in() && current_user_can("access_s2member_level2")) :
if (function_exists('wp_page_numbers')) :
wp_page_numbers();
endif;
else :
echo '<a href="/"><div class="show-more-bar">Show more videos</div></a>';
endif;
?>
[/code]

But it's generally not a good idea to try to mix the curly braces syntax with the colon/endif syntax, as that's just asking for confusion. ?
Copy linkTweet thisAlerts:
@NogDogJun 14.2011 — And upon further review, there's really no need for the inner if block (unless something else is going on there that you've not shown us):
[code=php]
<?php
if (is_user_logged_in() && current_user_can("access_s2member_level2")
&& function_exists('wp_page_numbers')) {
wp_page_numbers();
} else {
echo '<a href="/"><div class="show-more-bar">Show more videos</div></a>';
}
?>
[/code]
Copy linkTweet thisAlerts:
@Master00authorJun 14.2011 — Thanks! That got it to work properly. PHP syntax is just plain confusion for me.
×

Success!

Help @Master00 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...