Forums

conditional tag php if content is blank (2 posts)

  1. gmisen
    Member
    Posted 3 months ago #

    can someone explain why this code is breaking my page?

    <?php
    $post_id = 2348;
    $queried_post = get_post($post_id);
    $title = $queried_post->post_title; 
    
    if !emptyempty($queried_post->post_content)
    
    echo $queried_post->post_content
    
    else echo { ?>
    <div id="navigation"></div>
    <?php } ?>

    i want to display this certain post. But if theres nothing in the body of the post i want to not display it (because the post is styled with a border around it, so even if blank an empty box shows up) and show my navigation div instead. any thoughts?

  2. gmisen
    Member
    Posted 3 months ago #

    woops just had a revelation and figured it out, nevermind

    <?php
    $post_id = 2348;
    $queried_post = get_post($post_id);
    $title = $queried_post->post_title; 
    
    if (empty($queried_post->post_content)) { ?>
    
    <div id="navigation"></div>
    <?php } else { ?>
    <div class="firstpost"><?php echo $queried_post->post_content ?></div>
    <?php } ?>

Reply

You must log in to post.

About this Topic