WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Avoid pictures on the frontpage/category pages (7 posts)

  1. Mads Phikamphon
    Member
    Posted 6 years ago #

    Hi,

    I'm using the "more" tag to avoid showing all of my posts on the frontpage/category pages.

    Problem is that some of my posts have a picture in the beginning and that the pictures are shown on the frontpage/category pages.
    (see here: http://www.asiden.dk/)

    Is there a way to modify the code, so post pictures aren't shown on the frontpage/category pages?

    Thanks, Mads

  2. DesignsbyVishal
    Member
    Posted 6 years ago #

    the easiest way that i can think of would be to use css

    set a unique class for the divs where you don't want the images to appera (e.g. noimg);

    then in css:

    .noimg img { display:none; }

  3. Mads Phikamphon
    Member
    Posted 6 years ago #

    Yes, but they should only be gone on the front page/category pages, not on the individual post pages.

    If I use the CSS solution, I need some way of telling WP which image class to use where.

  4. Kafkaesqui

    Posted 6 years ago #

    Actually, no need to set a class for the images specifically. You can slip this into your theme's header.php (or where ever the <head> sits in your templates):

    <?php if( !is_single() && !is_page() ) : ?>
    <style type="text/css">
    <!--
    .post img {
    	display: none;
    }
    //-->
    </style>
    <?php endif; ?>

    Make sure, if necessary, to modify the .post class to one you use for your posts, typically a class for a div element each post resides in in the layout.

    For a purely PHP method that removes rather than hides the images through css, replace:

    <?php the_content(); ?>

    in any templates where you do not want images displayed with:

    <?php echo preg_replace( '/<img[^>]*>/i', '', apply_filters('the_content', get_the_content()) ); ?>

    In the case where say single.php and page.php templates are missing in action for a theme:

    <?php
    if( is_single() || is_page() ) :
    	the_content();
    else :
    	echo preg_replace( '/<img[^>]*>/i', '', apply_filters('the_content', get_the_content()) );
    endif;
    ?>
  5. jrawle
    Member
    Posted 6 years ago #

    The category pages usually use the_excerpt() rather than the_content(), so shouldn't show any images anyway. You could also try this on your front page.

  6. Mads Phikamphon
    Member
    Posted 6 years ago #

    Outstanding answers! Thank you everybody, it works now.

  7. Anonymous
    Unregistered
    Posted 6 years ago #

    hi, i have a problem with assigning a class to an image in wordpress. i know that the code should look like this to have an image displayed the way i wan to:

    <img src="http://www.pictures.reuters.com/doc/RTR/Media/TR6/F/0/I/U/RTX8708.jpg" height="136" width="180" class="left"/>

    i can easily add the class when i'm logged in as an administrator, but when i try to do it when i'm logged in as an author, this part of class="left" is being deleted automatically. please advise.

Topic Closed

This topic has been closed to new replies.

About this Topic