• FrauStaenki

    (@fraustaenki)


    Dear Huemans!!

    Is there a way to make HUEMAN show the (first?) images of the post, NOT the FEATURED IMAGE on the page? I. E., if you don’t use the feature image function??

    Greets
    Daniel

Viewing 7 replies - 1 through 7 (of 7 total)
  • bdbrown

    (@bdbrown)

    Hi Daniel. This article discusses one way to address that issue.

    Thread Starter FrauStaenki

    (@fraustaenki)

    Thank you very much!

    The question is: Is there a way, to address this problem, if someone doesn’t work with FEATURED IMAGES at all. Or is FI the way to go in the future??

    I mean, if I just want my posts to be shown, with the images I include, this what be my way to work with a personal blog …

    bdbrown

    (@bdbrown)

    Is this for the home page? Category pages? Single post pages?

    Thread Starter FrauStaenki

    (@fraustaenki)

    On all pages.

    And additionally:

    How to use Thumbnails as Featured images??

    THANK YOU!!

    bdbrown

    (@bdbrown)

    Here’s a possible solution. First a couple of caveats:
    1. You need to be running a child theme. If you’re not, you can download one in Theme Options under the Help tab in the upper righthand corner.
    2. This code will only work with images that are attached to the post; i.e. images that are Uploaded directly to the post from within the Media Manager. This is not the same as inserting media into the post content. The code does NOT work with images that are inserted into the post content.
    3. I also tested this with a standard WP gallery and it pulled the image in the gallery with the lowest ID.

    The changes below need to be applied to content.php. If you’re using the Standard Blog List they would also need to go into content-standard.php. I didn’t test this with Featured Posts but, if you’re using that option, you’d also need to edit content-featured.php.

    Copy the content file to your child theme.
    Locate the following block of code at the top of the file:

    <?php if ( has_post_thumbnail() ): ?>
    	<?php the_post_thumbnail('thumb-medium'); ?>
    <?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; ?>

    The logic above says:
    – If there’s a featured image, show it
    – Else, if the placeholder option is on, show it
    – Else no image
    We’re going to insert a new block of code after the featured image logic to check for images attached to the post. If there is one, or more, display the first one. Add the new block of code in the middle so the entire block looks like this:

    <?php if ( has_post_thumbnail() ): ?>
    	<?php the_post_thumbnail('thumb-medium'); ?>
    
    <?php else: ?>
    	<?php
    	 // GET THE FIRST IMAGE ATTACHED TO THE POST OR THE LOWEST IMAGE ID IN A GALLERY.
    	 // THIS ONLY WORKS FOR IMAGES THAT ARE UPLOADED TO THE POST IN THE MEDIA MANAGER, NOT INSERTED INTO THE POST CONTENT FROM THE MEDIA LIBRARY!!
    		$args = array(
    		'order'          => 'ASC',
    		'orderby'        => 'menu_order',
    		'post_type'      => 'attachment',
    		'post_parent'    => $post->ID,
    		'post_mime_type' => 'image',
    		'post_status'    => null,
    		'numberposts'    => 1,
    		);
    		$img_attachments = get_posts($args);
    	?>
    	<?php if ($img_attachments): ?>
    		<?php foreach ($img_attachments as $attachment) {
    			echo wp_get_attachment_link($attachment->ID, 'thumb-medium', false, false);
    		} ?>
    	<?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; ?>

    Let me know how that works.

    Thread Starter FrauStaenki

    (@fraustaenki)

    Hi bdbrown!

    It works very well! Awesome!! I also learned, how cool child themes are and that working with children is not that complicated (as in reality;-)).

    Besides: There are some plug-ins, that do the same things:

    “Easy add thumbnails” and “refresh thumbnails” (or something like that!

    Anyways: THANK YOU VERY, VERY MUCH!!!

    Greets
    Daniel

    bdbrown

    (@bdbrown)

    Glad to hear it’s working. If you don’t need any further assistance here please mark this topic as Resolved. Thanks.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Normal, not featured images’ is closed to new replies.