• Resolved kirasiris

    (@kirasiris)


    Hello everyone, it may be absurd to even ask because hiding a div is easy to do on loops,etc. However this time I’m not doing a while loop, instead I’m doing something more like just a “check if” on my front-page file, and it is not working there.

    Here is my code:

    
    <!-- Page content -->
    <?php if(have_posts()) : the_post(); ?>
    <div class="container-fluid" id="kevin_container">
    <div class="row">
    <div class="container" id="kevin_page_container">
    <!------ Child Pages and Parent Page --->
    <?php if(page_is_parent() || $post->post_parent > 0) : ?>
    <div class="pagination pull-right">
    <li>
    <span class="parent-link">
    <a href="<?php echo get_the_permalink(get_top_parent()); ?>"><?php echo get_the_title(get_top_parent()); ?></a>
    </span>
    <?php
    $args = array(
    'child_of' => get_top_parent(),
    'title_li' => ''
    );
    ?>
    <?php wp_list_pages($args); ?>
    </li>
    </div>
    <div class="clearfix"></div>
    <?php endif; ?>
    <article>
    <?php the_content(); ?>
    </article>
    </div>
    </div>
    </div>
    <?php endif; ?>
    

    I would like to say that I’m trying to show content from a page, not a post.

    Thanks

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

    (@alchymyth)

    which div exactly are you trying to hide?

    as the code is now, all the divs in your html will be hidden if there is no page.

    Thread Starter kirasiris

    (@kirasiris)

    I want to actually hide all divs that are in the code above, you can check my website to see what I’m talking about. It is supposed to be hidden(as right now has no content), right? unfortunately it is not.
    This is my website
    As you will see, theres a big empty div :/ .

    Thaks

    Hello @kirasiris,

    You can simply wrap all your code in below condition.

    global $post;
    if($post->post_content){
    // your code block
    }

    Let, me know if there is anything.

    Thread Starter kirasiris

    (@kirasiris)

    It’s not working :/ . It now hides all the div when there is content on it; what I want is to have hidden just when there is not.
    Thanks.

    EDIT: It’s working now. Thanks

    • This reply was modified 7 years ago by kirasiris.

    good luck ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to properly hide div when if have_post is empty.’ is closed to new replies.