• Hello,

    I want to display some text on my website, whenever the page with a specific name is published (i keep this page as a draft when i dont want to show this content)

    How do i do that?

    I thought this would do the trick;

    <?php if(get_page_by_title('Storing')) : ?>
    <h3>test</h3>
    <?php endif;?>

    But this shows the post under all circumstances, since it only seems to check if the page excists.

    Any clues?

Viewing 5 replies - 16 through 20 (of 20 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Ok, that code is wrong. Here is the correct version(I think):

    <?php
    // if you want to show the content of your draft post
    
    $limit = 40; // this is 40 words
    $content = explode(' ', $draft_content);
    if (count($content) > $limit) {
    $content = implode(' ', array_slice($content, 0, $limit)) . '...';
    } else { $content = $draft_content; }
    echo $content;
    ?>

    I need some coffee!

    Thread Starter sirtimo

    (@sirtimo)

    Get yourself some coffee! Thanks for the great help ?? it’s up and running!

    keesiemeijer – wonderful piece of code, thanks! Do you think you might be able to help me? I’d like to only display a text and have it link to the actual content, so I’d need to get the post url, not it’s content and echo that into a link:

    “>link text

    Thanks in advance!

    the code didn’t show, now it should:

    <a href="<?php the_post_link ?>">link text</a>

    Figured it out myself; but understanding the “published” status part was key. Thanks again!!!!!

    In case anyone else needs something similar.

    <?php
     $dd_post_id = 1;
     $dd_check_post_id = get_page( $dd_post_id );
     $dd_post_url = get_permalink( $dd_post_id );
    
      if ($dd_check_post_id->post_status == 'publish') echo '<div><a href="'.$dd_post_url.'">'.$dd_post_title.'</a></div>';
    ?>
Viewing 5 replies - 16 through 20 (of 20 total)
  • The topic ‘How to check page STATUS?’ is closed to new replies.