Support » Theme: Customizr » Featured images to show in post

  • i have set all posts with featured image. but they do no show up inside the post , i.e when we are in the post.

    how can i show featured image of the post inside it?

Viewing 15 replies - 1 through 15 (of 15 total)
  • Go to Dashboard>Posts and select each post. Bottom right there is a Featured Images panel. Add it there using 270×250 recommended size

    Thread Starter hassan.Zia

    (@hassanzia)

    Sir i added featured images on every post. they can be seen as a thubmnail.
    http://bubbletrouble.ae/?p=627

    but when i click and enter a post images are not shown inside.
    http://bubbletrouble.ae/?p=292

    OK, that’s working as designed but I see what you’re requesting. Will need some php custom code.

    Thread Starter hassan.Zia

    (@hassanzia)

    can you guide?
    i have a child theme installed

    Copy folder parts to child theme, open class-content-post.php, delete all code, and paste code from:
    http://pastebin.com/ZzbgvXz4

    Thread Starter hassan.Zia

    (@hassanzia)

    the site is giving this error:
    Parse error: syntax error, unexpected ‘class’ (T_CLASS) in /home/projects/public_html/wp/wp-content/themes/customizer-child/parts/class-content-post.php on line 1

    should i copy all the files from parts folder as well? or just “class-content-post.php”

    You were given bad advice to replace the php file. If you’re not a programmer, it is not good practice to overwrite theme code, as it will be lost when you update the theme.

    The simple answer to your original question is that the theme is working as it was designed to work (differently from some other themes, I know). If you want the featured image to show in your post with the Customizr theme, then simply add it to the post.

    That is, add it as a featured image and then again as an image in the page.

    Again, I know that this is not how some other themes work, but it works for Customizr.

    Thread Starter hassan.Zia

    (@hassanzia)

    electric feet i think i can manage an over right in theme as i have a child theme installed.
    as adding image in every post will be a hactic work. i have more than 190 posts.
    so if there is a php override that can do what i am trying to please guide

    Well, waddayaknow? Just 4 days after my first php filter, I’ve discovered that this will do it for you:

    add_filter( 'tc_post_content', 'my_extra_image' );
    function my_extra_image() {
    	if ( has_post_thumbnail() ) { // check if the post has a featured image assigned to it.
      		the_post_thumbnail();
    	}
    }

    Add to your functions.php file.

    You can also experiment with:

    add_filter( '__after_content', 'my_extra_image' );
    function my_extra_image() {
    	if ( has_post_thumbnail() ) { // check if the post has a featured image assigned to it.
      		the_post_thumbnail();
    	}
    }

    and

    add_filter( '__before_content', 'my_extra_image' );
    function my_extra_image() {
    	if ( has_post_thumbnail() ) { // check if the post has a featured image assigned to it.
      		the_post_thumbnail();
    	}
    }

    You then need to style it, of course — if someone could show us a way to add a class to the image, that would be great.

    You were given bad advice to replace the php file. If you’re not a programmer, it is not good practice to overwrite theme code, as it will be lost when you update the theme.

    Copy folder parts to child theme, open class-content-post.php, delete all code, and paste code from:
    http://pastebin.com/ZzbgvXz4

    Your method is:”Why simple, when it can be complicated.”

    No, my method adds to the theme’s code, rather than replacing it. Replaced code will be overwritten when the theme is updated. And then if you try to overwrite again with the old code, you risk breaking the theme completely.

    Adding code to the child theme’s functions.php is the recommended way to add or change functionality.

    That’s what makes it the simple solution in the long run.

    Thread Starter hassan.Zia

    (@hassanzia)

    a little guide please. so i make a file “functions.php” in my child theme. and add the above mentioned code. right? no need to add the whole functions.php code in the new one?

    Thread Starter hassan.Zia

    (@hassanzia)

    Sweet. it worked. Genius.
    one question though.
    how to add the image after the heading. in the body/text area

    Thread Starter hassan.Zia

    (@hassanzia)

    let me refine the question:

    how to add the image after the heading. in the body/text area and resized to a thubmnail image. e.g 150px by 150px

    Ha. I was afraid that would be your next question 🙂

    But what do you know…I worked it out. This new-found filter knowledge is really cool.

    How did I work this out?

    • Well, I saw that the post header had a style of “entry-title”, so I fired up EasyFind (great tool (MacOSX), to look inside the files inside the Customizr folder.
    • Found “entry-title” in the class-content-headings.php file.
    • Looked around in there for “apply_filters” functions. This is one of the magic formulas for finding “hooks” in WordPress that you can hang your code on.
    • There’s a line in there that says:
      echo is_singular() ? apply_filters( 'tc_content_headings_separator', '<hr class="featurette-divider '.current_filter().'">' ) : ''; which basically means “if we’re looking at a single post (rather than the list of posts) add a line under the title”. But clever @nikeo, he doesn’t just add the line, he adds it with a filter (so you can remove it if you want).
    • So this is where you can hang your filter: deeper inside the post than the previous filter allowed. Not really that elegant hanging your picture off a vertical line, but it works.

    So your code now becomes:

    add_filter( 'tc_content_headings_separator', 'my_extra_image' );
    function my_extra_image() {
    	if ( has_post_thumbnail() ) { // check if the post has a featured image assigned to it.
      		echo '<hr class="featurette-divider">';
      		echo the_post_thumbnail();
    	}
    }

    Perhaps @nikeo or @acub could take a look at that code and see if it’s robust enough and won’t have unintended consequences elsewhere. (I feel I should be using something more exotic than “echo”, for a start!.)

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Featured images to show in post’ is closed to new replies.