sterndata on "How can I make featured image optional on post pages?"

ساخت وبلاگ

Currently when I make a new post it grabs the same flower image unless I set the featured image to another picture. Is there a way to have the featured image optional rather than always having to have one. If i select a featured image I want it in the same exact place its in now, I just want the option of having one or not.

Here is the link:

http://www.houstonhypnosis.com/hypnosis-blog/history-of-hypnosis-infographic/

You seem to be using a custom theme. Do you know where you obtained it from?

no it was made by a developer here in houston,,,what should i look for to change it and where? css stylesheets?

in single.php this seems to be the code <div class="blg_img">
<?php
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
if( $image=='') {?>
<img src="<?php echo get_template_directory_uri();?>/images/blg1.jpg" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" />
<?php } else {?>
<img src="<?php echo $image[0] ?>" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" />
<?php } ?>
</div>

because blg1.jpg is the file it grabs

so you could change that to

if (has_post_thumbnail()) { the_post_thumbnail(); } else { //whatever you want to do if there's none }

jesyna
Member
Posted 58 minutes ago #

stedata thank you but I am not sure exactly how to change it in the single.php from what you wrote,,,

jesyna
Member
Posted 55 minutes ago #

If there is no featured image selected I would like the text of the post to begin at the top of the page

jesyna
Member
Posted 52 minutes ago #

so do I change this:

if( $image=='') {?>
<img src="<?php echo get_template_directory_uri();?>/images/blg1.jpg" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" />
<?php }
to this:

if (has_post_thumbnail()) {
the_post_thumbnail();
}

jesyna
Member
Posted 49 minutes ago #

or do I change just this piece:

if( $image=='') {?>
<img src="<?php echo get_template_directory_uri();?>/images/blg1.jpg"

to:

if (has_post_thumbnail()) {
the_post_thumbnail();
}

leave the "else" case empty (but leave it there in case you change your mind later. :-)

I'd try first replacing what you pasted with this

if (has_post_thumbnail()) { echo '<div class="blg_img">'; the_post_thumbnail(); echo '</div>'; } else { // do nothing }

jesyna
Member
Posted 13 minutes ago #

Thank you stedata,,,you absolutely rock!!!

Stedata that took care of it on the post page, but on the blog home page where it has the snippets of the posts, it is still grabbing that old flower image picture. Any ideas how I would make it stop grabbing the photo for there as well? Here is the link:

http://www.houstonhypnosis.com/hypnosis-blog/

install the plugin "show current template" so you can see what PHP file is used to render that page, then do something similar to what you did for single.php

WordPress ...
ما را در سایت WordPress دنبال می کنید

برچسب : نویسنده : استخدام کار wpss بازدید : 249 تاريخ : چهارشنبه 9 تير 1395 ساعت: 22:23