WordPress.org

Ready to get started?Download WordPress

Forums

hide div when single post is displayed (3 posts)

  1. akdream
    Member
    Posted 3 years ago #

    Hi,

    As the title says I would like to have a div which is hidden when the post is displayed as a single post but shown on the main blog page.

    The idea is to have

    <div class="excerpt">Here the part I'd like to show up on the main blog page</div><!--more Read more...-->
    My post

    So on the main blog page the excerpt div would be displayed, people click on Read more then the single post is displayed without the excerpt div.

    Can this be done? Does this even make sense? I'm not so good at coding sorry, I still have to learn a lot.

    Thanks,
    Tim

  2. chinmoy
    Member
    Posted 3 years ago #

    use condition like

    <?php if(!is_single()): ?>
      <div class="excerpt">Here the part I'd like to show up on the main blog page</div><!--more Read more...-->
    My post
    <?php endif; ?>
  3. akdream
    Member
    Posted 3 years ago #

    Thank you for your answer. Unfortunately I didn't get it... :-(

    Anyway I ended up with having

    <?php if (is_single()) { ?>
    <style type="text/css">
    div.excerpt {display:none;}
    </style>;
    <?php } ?>

    posted right before the closing head tag in the header.php

    So if I add
    <div class="excerpt">Here the part I'd like to show up on the main blog page</div><!--more Read more...-->
    to my post all the content in the div will be displayed on the main blog page but not in the post itself once you view it as a single post. No matter what the div contains and no matter what post it's on.

    That's the result of my three hours of research... Maybe it's not the best solution to achieve what I wanted to achieve but it works the way I wanted it to work :-) At least I now can control what displays in the main blog page and what doesn't.

    Still don't know what the effect of this on the RSS Feed but I don't really mind about the RSS Feed...

    Regards,
    Tim

Topic Closed

This topic has been closed to new replies.

About this Topic