bfkouba
Member
Posted 2 years ago #
I'm VERY new at all of this. I would like to make a conditional statement in my sidebar that shows a piece of text if a page with a specified id is published (instead of draft or pending review)... so something like this:
<?php
if(page_is_published('293')){ ?>
<a href="/next-weeks-movies">Next Week's Videos</a>
<?php }else{} ?>
Can someone help me? Thank you!
- Ben
Totally untested but what about:
<?php
$page_id = 293;
if( get_page($page_id) ) { ?>
<a href="/next-weeks-movies">Next Week's Videos</a>
<?php }else{} ?>
http://codex.wordpress.org/Function_Reference/get_page
bfkouba
Member
Posted 2 years ago #
Seemed like it would... but wordpress still finds the page even if it's a draft.
I don't know. Basically I want to hide the link if the page is a draft. There's gotta be a way.
Anyone?
bfkouba
Member
Posted 2 years ago #
Hey I figured it out!
For anyone else wanting to the same things... here's what I got:
$page_id = 284; //the id of the page you're checking to see if it's published
$page_data = get_page($page_id);
if($page_data->post_status == 'publish'){ ?>
<!-- Put the HTML here that you want to display if the page is published -->
<?php }else{} ?>
bfkouba
Member
Posted 2 years ago #
btw... THANK YOU to esmi. That tip got me going in the right direction. I appreciate the support.
You're very welcome. :-) Thanks for posting a working solution.