• Resolved bfkouba

    (@bfkouba)


    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

Viewing 5 replies - 1 through 5 (of 5 total)
  • esmi

    (@esmi)

    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

    Thread Starter bfkouba

    (@bfkouba)

    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?

    Thread Starter bfkouba

    (@bfkouba)

    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{} ?>
    Thread Starter bfkouba

    (@bfkouba)

    btw… THANK YOU to esmi. That tip got me going in the right direction. I appreciate the support.

    esmi

    (@esmi)

    You’re very welcome. 🙂 Thanks for posting a working solution.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘conditional function if page exists’ is closed to new replies.