How to add featured image
-
Need help with adding featured images to the excerpts. Please help!
email [ redacted ]
-
Hi from France!
A correct excerpt with img sourcing works with WP 3.4.2.
Please See fleurons.fr/best-of/ (WP 342)With WP 3.5 too, but Related posts are include without linking. There are two bugs! Related post are not need at this place.
just1clic.fr/arrivages/We have to try to find an automatic excerpt pluging for mass publishing and/or make a correction with WP 3.5 use.
Have a nice day!
Yes I have Wp 3.5 and would love for the featured images to show.
Thanks, Great plug-in!
Hey Guys,
Give me a few minutes and I’ll throw together some code for you. / Eric
Alright guys, here’s how you can add the Featured Image to your Posts in Page template.
As you’ve already discovered, by default, we’re just showing the_title, the_excerpt, categories, tags, and the comment link.
If you wish to change the output to include the permalink, the first thing I’d recommend is changing the output template. Best way to do this is documented on the plugin site:
How do I change the output template
Simply copy theposts_loop_template.php
to your theme directory and make changes as necessary.You can even rename it – but make sure to indicate that in the shortcode using the template=’template_name.php’.
So, I’d start by copying the
posts_loop_template.php
to your theme directory.Then, open it up in an editor and you’ll probably see something like this:
<!-- Note: if you make changes to this file, move it to your current theme's directory so this file won't be overwritten when the plugin is upgraded. --> <!-- Start of Post Wrap --> <div class="post hentry ivycat-post"> <!-- This is the output of the post title --> <h2 class="entry-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <!-- This is the output of the excerpt --> <div class="entry-summary"> <?php the_excerpt(); ?> </div> <!-- This is the output of the meta information --> <div class="entry-utility"> <?php if ( count( get_the_category() ) ) : ?> <span class="cat-links"> <?php printf( __( '<span class="%1$s">Posted in</span> %2$s', 'twentyten' ), 'entry-utility-prep entry-utility-prep-cat-links', get_the_category_list( ', ' ) ); ?> </span> <span class="meta-sep">|</span> <?php endif; ?> <?php $tags_list = get_the_tag_list( '', ', ' ); if ( $tags_list ): ?> <span class="tag-links"> <?php printf( __( '<span class="%1$s">Tagged</span> %2$s', 'twentyten' ), 'entry-utility-prep entry-utility-prep-tag-links', $tags_list ); ?> </span> <span class="meta-sep">|</span> <?php endif; ?> <span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'twentyten' ), __( '1 Comment', 'twentyten' ), __( '% Comments', 'twentyten' ) ); ?></span> <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?> </div> </div> <!-- // End of Post Wrap -->
To add the featured image, you can use the_post_thumbnail function:
<?php the_post_thumbnail( $size, $attr ); ?>
So, in a case where you wanted to add the thumbnail sized image as a featured image to your loop, you’ll need to add that function in the template file where you’d like it to appear.
Here’s an example:
<!-- Note: if you make changes to this file, move it to your current theme's directory so this file won't be overwritten when the plugin is upgraded. --> <!-- Start of Post Wrap --> <div class="post hentry ivycat-post"> <!-- This is the output of the post title --> <h2 class="entry-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <!-- This is the output of the excerpt --> <div class="entry-summary"> <?php the_excerpt(); ?> </div> <!-- This will output of the featured image thumbnail --> <div class="featured-image"> <?php the_post_thumbnail( 'thumbnail' ); ?> </div> <!-- This is the output of the meta information --> <div class="entry-utility"> <?php if ( count( get_the_category() ) ) : ?> <span class="cat-links"> <?php printf( __( '<span class="%1$s">Posted in</span> %2$s', 'twentyten' ), 'entry-utility-prep entry-utility-prep-cat-links', get_the_category_list( ', ' ) ); ?> </span> <span class="meta-sep">|</span> <?php endif; ?> <?php $tags_list = get_the_tag_list( '', ', ' ); if ( $tags_list ): ?> <span class="tag-links"> <?php printf( __( '<span class="%1$s">Tagged</span> %2$s', 'twentyten' ), 'entry-utility-prep entry-utility-prep-tag-links', $tags_list ); ?> </span> <span class="meta-sep">|</span> <?php endif; ?> <span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'twentyten' ), __( '1 Comment', 'twentyten' ), __( '% Comments', 'twentyten' ) ); ?></span> <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?> </div> </div> <!-- // End of Post Wrap -->
I hope that helps.
Eric
I can’t find the posts_loop_template.php. Where is it?
Many thanks.
ccmascarelli,
It’s in the plugin’s directory. If you wish to customize it, move it to your theme’s directory first.
e
How to wrapp <?php the_excerpt(); ?> text around <?php the_post_thumbnail( ‘hotleft’ ); ?> ?
Hey C3dRy2K,
How to wrapp
<?php the_excerpt(); ?>
text around<?php the_post_thumbnail( 'hotleft' ); ?>
?Sounds like you’re asking a style question; am I right?
If so, can you provide a link or screenshot?
If style’s the issue, I’m imagining you’ll probably use CSS floats to have text ‘flow’ around an image.
Hope that helps.
EricThank you Eric, i already solved the issue. Now, i need one last thing, to display a custom text if there is no post to display by specific tag and/or category.
I copied the file to my themes directory and replaced all with the code provided above. I’m still not seeing the featured image with my post excerpts like I would with a blog page. Did I miss a step?
I figured out the step I missed … I needed to change “twentyten” to my theme’s name! Some additional customizations I used in case it helps anyone:
This was added to functions.php in order to make the image link to the post:
/** Link all post thumbnails to post permalink */</p> <p>add_filter( 'post_thumbnail_html', 'my_post_image_html', 10, 3 );</p> <p>function my_post_image_html( $html, $post_id, $post_image_id ) {<br /> $html = '<a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( get_post_field( 'post_title', $post_id ) ) . '">' . $html . '</a>';<br /> return $html;</p> <p>}
Also, this is what I came up with for aligning the image to the left of the excerpt (I put its DIV inside the other DIV) and making it a custom size:
<!-- This is the output of the excerpt --><br /> <div class="entry-summary"><br /> <!-- This will output of the featured image thumbnail --><br /> <div class="featured-image"><br /> <?php the_post_thumbnail( array(180,9999), array('class' => 'alignleft')); ?><br /> </div><br /> <?php the_excerpt(); ?><br /> </div><br />
jodzeee: Glad you got this sorted out. Let us know if you have questions.
i need one last thing, to display a custom text if there is no post to display by specific tag and/or category.
C3dRy2K: I’d do this inside your category or tag template, most likely. As with many things, there are several ways you could approach this, but I’d opt for the easy route and just have a fallback within the appropriate template file.
Make sense?
Hello!
A little stumped about how to copy the posts_loop_template into my theme files. Just copy into my stylesheet? At any particular location? I tried and it doesn’t seem to work, so I assume I’m incorrect.
I’m a newbie, so a basic breakdown would be ideal. I tried researching this myself but I’m coming up empty…and more confused!
Thanks so much for your time, loving the plugin & active support area!
Caitlin
Hey caitlinstangelo,
Okay, so two things:
1. In the future, if you wouldn’t mind starting a new support thread, it’s helpful because we don’t mix topics and I can make sure that unaddressed questions are answered.
Some of these older support posts are marked as resolved and don’t automatically move to unresolved when new posts are added.
2. Onto your question . . .
A little stumped about how to copy the posts_loop_template into my theme files. Just copy into my stylesheet? At any particular location? I tried and it doesn’t seem to work, so I assume I’m incorrect.
I’m a newbie, so a basic breakdown would be ideal. I tried researching this myself but I’m coming up empty…and more confused!
So this plugin is really geared a bit more for folks with some CSS, HTML and (if needed) PHP skills. Don’t need much, but it helps.
That said, here’s what you do:
- Using your file manager, or FTP, copy the
posts_loop_template.php
file from the post-in-page plugin directory over to your theme’s main directory. Not sure what your whole path will be, but you’ll be looking for something like/wp-content/plugins/posts-in-page/posts-loop-template.php
and will copy it to/wp-content/themes/your-theme-name/
- Once you’ve done that, open the file that you’ve just copied to your theme directory and change as you see fit.
- Save your file and test.
- If you need multiple custom Posts in Page templates, you can even rename the posts_loop_template.php file and call it inside the shortcode by name using
template='template_name.php'
Thanks so much for your time, loving the plugin & active support area!
My pleasure. Glad it’s helping you. ??
i use this code, and i want to retrive a specific text if there’s nothing to display.
<!-- NOTE: If you need to make changes to this file, copy it to your current theme's main directory so your changes won't be overwritten when the plugin is upgraded. --> <!-- Start of Post Wrap --> <div class="post hentry ivycat-post"> <!-- This will output of the featured image thumbnail --> <a href="<?php the_permalink() ?>" rel="bookmark"> <?php if(get_option('thumbok')!="yes"):?> <img src="<?php bloginfo('template_directory'); ?>/includes/timthumb.php?src=<?php echo get_post_meta($post->ID, 'image',true) ?>&w=100&h=68&zc=1" class="thepart1bimg"/> <?php endif?> <?php if(get_option('thumbok')!="no"):?> <span class="thepart1bimg"><?php the_post_thumbnail( 'archiveimg' ); ?></span> <?php endif?> </a> <div class="ptitle"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div> <!-- This is the output of the EXCERPT --> <div class="entry-summary"> <?php the_excerpt(); ?> </div> <div class="meta_author">Pe <?php the_time('j M Y'); ?> | Cu <a href="#comments"> <?php comments_number('0 Comentarii','1 Comentariu','2 Comentarii'); ?> </a> </div> <br style="clear: both;" /> </div> <!-- // End of Post Wrap -->
Something combine with this:
<?php else : ?> <h2 class="center">Not Found</h2> <p class="center"> <?php _e("Sorry, but you are looking for something that isn't here."); ?></p>
- Using your file manager, or FTP, copy the
- The topic ‘How to add featured image’ is closed to new replies.