Viewing 13 replies - 1 through 13 (of 13 total)
  • Hi tuhinbiswas98. You can do this using the WP in_category() function.

    1. Copy content-featured.php from the parent theme to your child theme.

    2. At the top of the file you’ll see this block of code:

    <?php if ( has_post_thumbnail() ): ?>
    	<?php the_post_thumbnail('thumb-large'); // only difference to content.php ?>
    <?php elseif ( ot_get_option('placeholder') != 'off' ): ?>
    	<img src="<?php echo get_template_directory_uri(); ?>/img/thumb-medium.png" alt="<?php the_title(); ?>" />
    <?php endif; ?>

    3. Add one line before and one line after so you end up with this:

    <?php if ( is_category('my-category') ) : ?>
    <?php if ( has_post_thumbnail() ): ?>
    	<?php the_post_thumbnail('thumb-large'); // only difference to content.php ?>
    <?php elseif ( ot_get_option('placeholder') != 'off' ): ?>
    	<img src="<?php echo get_template_directory_uri(); ?>/img/thumb-medium.png" alt="<?php the_title(); ?>" />
    <?php endif; ?>
    <?php endif; ?>

    4. Change ‘my-category’ to the name of your category.

    Thread Starter tuhinbiswas98

    (@tuhinbiswas98)

    i am trying this on my ths site https://pomm.tk/ but its not worrking :O

    I assumed you were talking about the images on the featured posts. If you’re not displaying featured posts then we need to do something differently. Where is it that you want to control the image display? On the category archive pages? The single post pages? Somewhere else?

    Thread Starter tuhinbiswas98

    (@tuhinbiswas98)

    i want to show that 2 category featured image in home page + Related Posts and Widgets just 2 category and after doing that now my featured image in my post Widgets but i want it to be show in home page + Related Posts to ty for help ??

    featured image in home page

    Is that the images on the Featured Posts at the top of the home page? Or the images on all the other posts on the home page? Or both?

    Related Posts

    OK, got that.

    Widgets

    Which widgets? There are several.

    Thread Starter tuhinbiswas98

    (@tuhinbiswas98)

    its showing featured image AlxPosts and AlxTabs Widgets ….. i want to show my 2 category featured image just like is show in your Theme without any css in home page and in search normal featured image ??

    OK, so if I understand your question:
    1. You don’t want to make any changes to the posts on the home page or the search page.
    2. In AlxPosts and AlxTabs widgets you want to display the post featured image, which it should do by default.
    3. You have several categories but you only want to show the featured image in AlxPosts and AlxTabs for the 2 categories that you specify. All posts in other categories would not show an image in the AlxPosts and AlxTabs widgets.

    Thread Starter tuhinbiswas98

    (@tuhinbiswas98)

    look at my site https://laughinghive.com/ ther 80% of post only have text and the dont realy need featured image so i remove featured image from my site using css but now i want to add 2 more categories the gona have top 10 funny list type of things so i will gona need featured image in post for that just 2 categories so i just want to know if ther any way to do that only 2 categories post show featured image but other all categories dont show featured image ?? this is what i am thinking sorry my eng not good lol and AlxPosts and AlxTabs widgets ther now showing featured image after i did that

    <?php if ( is_category(‘my-category’) ) : ?>
    <?php if ( has_post_thumbnail() ): ?>
    <?php the_post_thumbnail(‘thumb-large’); // only difference to content.php ?>
    <?php elseif ( ot_get_option(‘placeholder’) != ‘off’ ): ?>
    <img src=”<?php echo get_template_directory_uri(); ?>/img/thumb-medium.png” alt=”<?php the_title(); ?>” />
    <?php endif; ?>
    <?php endif; ?>

    so now i just need to add featured image in my home page:)

    Now it appears that there are featured images on almost all the posts on the home page. If you only want to control the featured images for the posts on the home page, and you’re using the Standard Blog layout, then you can use the information I originally posted above to modify content-standard.php (not content-featured.php) in your child theme and change the first line from this:

    <?php if ( is_category('my-category') ) : ?>

    to this (notice it’s in_category, not is_category):

    <?php if ( is_home() && in_category('my-category') ) : ?>
    Thread Starter tuhinbiswas98

    (@tuhinbiswas98)

    ?? i try that but its not working ??

    Thread Starter tuhinbiswas98

    (@tuhinbiswas98)

    i was looking for this and i got this code

    /*hides featured image in category view*/
    .category-50 .post-thumbnail img {
    display: none;
    }

    and its worrking ?? ty ty for help

    but idk how to edit this code to make my 2 category featured image and all other to make them hide :O

    You could try hiding them all then displaying them for the two categories you specify:

    post-thumbnail img {
      display: none;
    }
    .category-1 .post-thumbnail img, .category-2 .post-thumbnail img {
      display: block;
    }
    Thread Starter tuhinbiswas98

    (@tuhinbiswas98)

    ty ty for help it worrking realy ty ??

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘featured image’ is closed to new replies.