• 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

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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; ?>

    Thread Starter akdream

    (@akdream)

    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

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘hide div when single post is displayed’ is closed to new replies.