• 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

How to use post_id >

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 › How to use post_id >

This topic is: not resolved

Tagged: featured image, php, post_id, thumbnail

  • This topic has 7 replies, 4 voices, and was last updated 11 years, 7 months ago by majecdad.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • April 18, 2014 at 12:21 am #101103
    majecdad
    Member

    Hate to drop in just for help... but I am. 🙂

    I added some code to put the Featured image in the Post content, like this:

    /* Code to Display Featured Image on top of the post */
    add_action( 'genesis_before_entry_content', 'featured_post_image', 8 );
    function featured_post_image() {
    if ( ! is_singular( 'post' ) ) return;
    the_post_thumbnail('post-image');
    }

    But I want to ONLY do this for posts GOING FORWARD. I have 1600 old posts where an image was added manually. If I place this globally, I'll have two images on those 1600 posts. No bueno.

    Can't I do something to ONLY have a post with "post_ID > 18800" use this code?

    Thank you much in advance for any help. Have a great day.

    April 20, 2014 at 1:32 am #101370
    Davinder Singh Kainth
    Member

    I understand, you want to target specific post ID

    Use following for post and pages (where 315 is post / page id)

    if (is_post(array('317')))
    if (is_page(array('317')))

    in place of

    if ( ! is_singular( ‘post’ ) )


    Sunshine PRO genesis theme
    Need Genesis help? Davinder @ iGuiding Media | My Blog | Fresh Genesis Themes

    April 20, 2014 at 6:51 pm #101559
    majecdad
    Member

    Thanks, but no, I'm looking to target ALL ids AFTER a specific id. e.g. post_id > 18800

    Any guidance out there?

    Thanks.

    April 21, 2014 at 2:26 am #101595
    daymobrew
    Member

    You could try using the get_the_ID() function.

    /* Code to Display Featured Image on top of the post */
    add_action( ‘genesis_before_entry_content’, ‘featured_post_image’, 8 );
    function featured_post_image() {
      if ( ! is_singular( ‘post’ ) ) return;
      if (18800 > get_the_ID()) {
        the_post_thumbnail(‘post-image’);
      }
    }
    April 21, 2014 at 5:03 am #101604
    Gary Jones
    Member

    @daymobrew - almost, but your logic is inverted.

    add_action( 'genesis_before_entry_content', 'featured_post_image', 8 );
    /**
     * Code to Display Featured Image on top of the post, since specific post ID.
     *
     * @return null Return early if not a singular post, or post ID is too low.
     */
    function featured_post_image() {
    	if ( ! is_singular( 'post' ) || get_the_ID() <= 18800 ) {
    		return;
    	}
    
    	the_post_thumbnail( 'post-image' );
    }

    WordPress Engineer, and key contributor the Genesis Framework | @GaryJ

    April 21, 2014 at 10:13 am #101667
    majecdad
    Member

    Excellent. The || get_the_id was where I couldn't figure structure.

    Only question remaining is if I want the code to only apply where the post ID is GREATER than 18800, should the code be:

    get_the_id() >= 18800 (instead of <=)?

    Thank you.

    April 21, 2014 at 10:18 am #101668
    Gary Jones
    Member

    Yes, if the rest of the logic was like that, but it's not.

    It's usually better practice to return early for any unfavourable conditions, so that what's left only applies to favourable conditions.

    So my code basically says "If it's not a single post, or the ID is less than or equal to 18800, then return and do nothing. For anything else (that is, posts with ID greater than 18800), go ahead and do something (here, show a post thumbnail)."

    The benefit is that you don't end up nesting and indenting code for each condition or wrapping the whole of the contents of the function in a giant condition.

    Return early when you can for cleaner code.


    WordPress Engineer, and key contributor the Genesis Framework | @GaryJ

    April 21, 2014 at 10:29 am #101673
    majecdad
    Member

    Ahhh, I see. I love that I learn something every day. Being self-taught, and doing 'cut-and-paste' code, even after several years, there is still so much to learn. 🙂

    Thank you all who replied, especially Gary, for not just the code, but as importantly the explanation of why it does what it does. I really appreciate it.

    Have a great day.

  • Author
    Posts
Viewing 8 posts - 1 through 8 (of 8 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

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

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2025 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