• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Features images on posts and text on blog page

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › Features images on posts and text on blog page

This topic is: resolved

Tagged: blog post, featured image, html5, php

  • This topic has 15 replies, 3 voices, and was last updated 7 years, 10 months ago by sbrody.
Viewing 16 posts - 1 through 16 (of 16 total)
  • Author
    Posts
  • July 20, 2015 at 4:03 am #159867
    sbrody
    Member

    Hi all
    I have a couple of problems and wonder if anyone can help. Both questions relate to this site: http://alexbelcourt.com/new/blog-home/
    I'm using my own child theme of the Genesis Framework.

    1. I am trying to make featured images appear on posts and have added lots of different versions of code to my child theme functions.php but it won't work. Here's what I have currently:

    /* Code to Display Featured Image on top of the post */
    add_action( 'genesis_entry_content', 'featured_post_image', 8 );
    function featured_post_image() {
    if ( !is_singular( array( 'post', 'page' ) )) return;
    the_post_thumbnail('large');
    //you can use medium, large or a custom size
    }

    2. I am also trying to add some text to the top of the blog listing page. I have created a new file page_blog.php and added the following code:

    <?php

    //* Template Name: Blog

    //* Show page content above posts
    add_action( 'genesis_loop', 'genesis_standard_loop', 5 );

    genesis();

    Again, this has had no effect.

    I'm completely stuck - does anyone know what the problem might be?
    Many thanks in advance!
    Cheers
    Sim

    http://alexbelcourt.com/new/blog-home/
    July 24, 2015 at 3:41 pm #160365
    Marcy
    Participant

    Using this for your blog post image should work:

    add_action( 'genesis_entry_content', 'custom_single_featured_image', 8 );
    function custom_single_featured_image() {
    
        if ( is_single() && has_post_thumbnail() ) {
    
        // Use featured image for blog posts
        echo genesis_image( array( 
        	'size' => 'large', 
        	'attr' => array( 
        		'class' => 'aligncenter entry-image' ) ) );
    
        }
    }

    As for the content on the Blog page, what you've done seems correct. I'm pasting the code again in case something is off:.
    Everything below goes in a file named page_blog.php that you place in your child theme folder where you have your functions.php and style.css.

    <?php
    //* Template Name: Blog
    
    //* Show page content above posts
    add_action( 'genesis_loop', 'genesis_standard_loop', 5 );
    
    genesis();

    Then go to the Editor for the page you have named Blog, and add some text to the editor. In the right sidebar, please make sure the under Page Attributes, the Template Blog is selected. Save again and clear any cache you have.

    It should work.


    Marcy | Amethyst Website Design | Twitter

    July 26, 2015 at 5:13 am #160484
    sbrody
    Member

    Thanks for your help Marcy.

    The content on the blog page now works correctly.

    Unfortunately the blog post images are still not appearing - I can see no logical reason why not. I'm pretty new to Genesis but it's frustrating that it is so difficult to do something so basic. Perhaps it's not for me!

    July 26, 2015 at 4:45 pm #160532
    Marcy
    Participant

    Are you saying that the featured images are still not appearing on the single posts?

    The code I posted above always works when I want featured image only on posts.
    When I want it on posts and pages, I use an array, like this:

    add_action( 'genesis_entry_content', 'custom_single_featured_image', 8 );
    function custom_single_featured_image() {
    
        if ( is_singular(array( 'post', 'page' ) ) && has_post_thumbnail() ) {
    
        // Use featured image at kqp-page-image-size for blog
        echo genesis_image( array( 
        	'size' => 'large', 
        	'attr' => array( 
        		'class' => 'aligncenter entry-image' ) ) );
        }
    }

    You can try that instead. If it works for you, and you don't want featured images on pages, then replace this line with:
    if ( is_singular( 'post' ) && has_post_thumbnail() ) {


    Marcy | Amethyst Website Design | Twitter

    July 31, 2015 at 9:38 am #161061
    sbrody
    Member

    Thanks again for your help.

    Unfortunately, images are still not appearing on either posts or pages - I've tried both versions of the code.

    It's left me scratching my head. I'm wondering if a plugin or other setting might be affecting it - although I only have a few very standard plugins in use.

    July 31, 2015 at 9:45 am #161062
    Marcy
    Participant

    I see images on single posts with the classes from the code above.

    Maybe you need to clear your browser cache to see it yourself?


    Marcy | Amethyst Website Design | Twitter

    July 31, 2015 at 9:57 am #161067
    sbrody
    Member

    Do you mean on the blog listing page or on individual blog posts? I'm still not seeing them on individual pages.
    Thanks
    Sim

    July 31, 2015 at 10:21 am #161074
    Marcy
    Participant

    You're correct; I was on a wrong page.
    There is something that's interring as you suggested, so it's a matter of figuring out what priority will work for what you have.

    Try this; it has a higher priority (7) now, so that may be needed.

    add_action( 'genesis_entry_content', 'custom_single_featured_image', 7 );
    function custom_single_featured_image() {
    
        if ( is_singular(array( 'post', 'page' ) ) && has_post_thumbnail() ) {
    
        // Use featured image at kqp-page-image-size for blog
        echo genesis_image( array( 
        	'size' => 'large', 
        	'attr' => array( 
        		'class' => 'aligncenter entry-image' ) ) );
        }
    }

    And if that doesn't work then try this:

    add_action( 'genesis_entry_header', 'custom_single_featured_image', 7 );
    function custom_single_featured_image() {
    
        if ( is_singular(array( 'post', 'page' ) ) && has_post_thumbnail() ) {
    
        // Use featured image at kqp-page-image-size for blog
        echo genesis_image( array( 
        	'size' => 'large', 
        	'attr' => array( 
        		'class' => 'aligncenter entry-image' ) ) );
        }
    }

    The last one should add the image to the entry header section above the title. That's probably not where you want it, but I need to see it.


    Marcy | Amethyst Website Design | Twitter

    July 31, 2015 at 10:30 am #161077
    sbrody
    Member

    I've tried both of those pieces of code and neither worked - I'm now working on this site btw http://simtest.uk/blogging/why-do-you-practice/
    Thanks

    July 31, 2015 at 11:13 am #161082
    Marcy
    Participant

    Can you please activate the Genesis Sample theme and add one of the code sections above to the sample theme functions.php?

    I have tested all the code I have given you, and they all should work.
    Perhaps there is something else in your theme.


    Marcy | Amethyst Website Design | Twitter

    July 31, 2015 at 11:47 am #161084
    sbrody
    Member

    Ok - I have activated Genesis Sample Theme and the images appear - so it must be something to do with the child theme I created... I've gone back to the child theme functions.php and stripped it back so it just contains this - is there anything obviously wrong with it?

    <?php
    add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles',1 );
    function enqueue_parent_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
    }

    add_action( 'genesis_entry_header', 'custom_single_featured_image', 7 );
    function custom_single_featured_image() {

    if ( is_singular(array( 'post', 'page' ) ) && has_post_thumbnail() ) {

    // Use featured image at kqp-page-image-size for blog
    echo genesis_image( array(
    'size' => 'large',
    'attr' => array(
    'class' => 'aligncenter entry-image' ) ) );
    }
    }

    July 31, 2015 at 11:56 am #161087
    scorpio9
    Member

    Hi Sim
    I don't know if this will help you... I was having the same problem as you and I tried all the code supplied here by Marcy so that suggested to me something else was going on, so with the code in place I deactivated ALL my plugins and refreshed the page, lo and behold the featured image appeared - this proved there was a conflict with one of them. From there I reactivated one plugin at-a-time an refreshed the page if the featured image was still showing I moved onto the next until I eventually found the one causing the conflict.

    I might be worth you trying this and see if there is a conflict with a plugin

    Good luck
    Lee

    July 31, 2015 at 4:46 pm #161105
    Marcy
    Participant

    Lee has good advice about deactivating the plugins to see if one of them is conflicting.
    That's the next step.

    The only other thing that I can suggest is to save your child theme functions.php with another name, and add the Genesis Sample functions.php. Add the code for the image on the posts pages, and then add the functions in your functions.php one at a time.

    I'm not able to troubleshoot your entire theme; you just have to start with what works, and add things gradually until you find what's causing the problem.


    Marcy | Amethyst Website Design | Twitter

    August 3, 2015 at 5:52 am #161232
    sbrody
    Member

    Thanks for your suggestions and help Lee and Marcy.
    I deactivated all my plugins but that didn't work.
    I then went through all the elements in the Genesis Sample functions.php and found this element was the crucial one:

    //* Add HTML5 markup structure
    add_theme_support( 'html5', array( 'search-form', 'comment-form', 'comment-list' ) );

    Once I added this, the images now appear.

    I'm not sure I quite understand why html5 support is needed to load a featured image but I'm pleased I've found the solution!

    Thanks again

    August 3, 2015 at 9:50 am #161275
    Marcy
    Participant

    Well, that explains a whole lot!

    The hook is different for non-html5.
    Instead of
    add_action( 'genesis_entry_content', 'custom_single_featured_image', 8 );
    you would need to use
    add_action( 'genesis_post_content', 'custom_single_featured_image', 8 );


    Marcy | Amethyst Website Design | Twitter

    August 11, 2015 at 10:37 am #162039
    sbrody
    Member

    Well, this has been a useful learning experience!
    Thanks again.

  • Author
    Posts
Viewing 16 posts - 1 through 16 (of 16 total)
  • The topic ‘Features images on posts and text on blog page’ is closed to new replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2023 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble