• 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

snippets

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 › General Discussion › snippets

This topic is: not resolved
  • This topic has 8 replies, 4 voices, and was last updated 10 years, 7 months ago by alexadark.
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • November 29, 2014 at 6:33 am #133199
    alexadark
    Member

    Hi,
    i am often wondering why genesis snippets are more complicated than writing in the classic wordpress way:
    ex:
    to display a fet img on single posts, i found that:

    add_action( 'genesis_entry_header', 'single_post_featured_image', 5 );
    
    function single_post_featured_image() {
    	
    	if ( ! is_singular( 'post' ) )
    		return;
    	
    	$img = genesis_get_image( array( 'format' => 'html', 'size' => genesis_get_option( 'image_size' ), 'attr' => array( 'class' => 'post-image' ) ) );
    	printf( '<a href="%s" title="%s">%s</a>', get_permalink(), the_title_attribute( 'echo=0' ), $img );
    	
    }

    Which works, but which i barely not understand (well i am not a php ninja)

    when i can write this without searching for a snippet as i perfectly understand what i am doing

    add_action( 'genesis_entry_header', 'wst_featured_image_single_post', 9 );
    
    function wst_featured_image_single_post() { 
    	if (  is_singular( 'post' ) )
    		{ ?>
    
    	<div class="featured-image">
    	<?php  the_post_thumbnail( 'featured'); ?>
    	</div>
    
    <?php  }
    }

    and here i can a markup around my featured img, in the other way, i have again to search another snippet, as i don't know how to do it.

    also why

    if ( ! is_singular( 'post' ) )
    		return; 

    instead of

    if (  is_singular( 'post' ) )
    		{ }

    which again is simpler (well for me!)

    same thing for displaying widget areas, why not use the wordpress classic way:

    <div class"widget-area>
    <?php ( dynamic_sidebar( 'widget area name' ) ) ?>
    </div>
    

    i find it easier than the genesis way, and the result is the same.

    So is there a reason to write it in the "genesis way" ? i am doing something wrong ?

    November 29, 2014 at 7:13 am #133201
    Brad Dalton
    Participant

    Link to the source of the code please


    Tutorials for StudioPress Themes.

    November 29, 2014 at 8:41 am #133206
    alexadark
    Member

    this is on your site 😉 http://wpsites.net/web-design/display-featured-image-before-or-after-entry-title-on-single-posts-pages/
    the other code is my way of writing

    November 29, 2014 at 9:13 am #133207
    cdils
    Participant
    if ( ! is_singular( 'post' ) )
    		return; 
    
    if (  is_singular( 'post' ) )
    		{ }

    The first statement says, "if it's not a single post", exit the function, otherwise carry on. The second statement says the opposite, "if it IS a single post" then do something..." The first statement is preferred because it exits the function immediately without reading further. In the second funtion, if it doesn't match the first conditional, it'll execute through the remainder of the function to see if there's anything else it needs to do.

    Regarding use of the curly braces... both statements are semantically, however in order to standardize usage, Nacin suggested in 2013 to always use braces. Not a big deal, just the direction that WordPress chose to standardize.

    Onto the thumbnail...

    You're correct that both ways accomplish basically the same thing, but what I like about the Genesis way is:

    * The genesis_get_image() encapsulates both the has_post_thumbnail conditional check (which the other code example should have to prevent that html markup printing in the event of no thumbnail. You can get the same output with less code.

    Also:

    * I (personally) prefer not to escape PHP (end curly bracket) and go back to HTML for such a small a small amount of HTML. The Genesis version is more readable. Of course, you could refactor the second code example to do that, so that's not a Genesis thing, just a coding preference

    The Sidebar:

    Using genesis_widget_area() nets you the advantage of including contextual HTML5 markup around the widget (assuming your site supports HTML5), so no need to manually write out those divs with hard-coded classes.

    Good questions. Hope that helps.

    Carrie


    Have you been helped in this forum? Pay it forward and answer someone else’s question. I bet you’ll know the answer to at least one question. 🙂

    I host a weekly WordPress-focused podcast called Office Hours. I tweet @cdils.

    November 29, 2014 at 9:30 am #133210
    alexadark
    Member

    Thank you very much Carrie, that's help a lot 🙂
    so i will use the genesis functions, but as i understand there can be coding preferences
    i prefer escaping php, as it's more readable with the code coloring etc...
    🙂

    November 29, 2014 at 12:41 pm #133222
    alexadark
    Member

    Well i'm trying to use genesis_get_image, but don't work...or don't know how to write it...

    
    	<div class="featured-image">
    	<?php  genesis_get_image(array ('size' => 'featured-big')); ?>
    	</div>
    November 30, 2014 at 1:25 am #133249
    Sridhar Katakam
    Participant

    A few links that might help:

    How to display Featured image in single Posts in Genesis

    https://dl.dropboxusercontent.com/u/2503558/GenesisWP/code-snippets.html#Image%20Functions%20examples

    http://designsbynickthegeek.com/tutorials/genesis-explained-image-functions


    Genesis Tutorials | Follow me on Twitter

    November 30, 2014 at 9:48 am #133259
    alexadark
    Member

    Thanks Sridhar,
    i have seen all that, and understood, but don't know why don't work with genesis_get_image , anyway i will keep the_post_thumbnail for this site; and will use it on the next

    Another question, when you make an archive page for a CPT, how do you link this page in the menu ?
    a part putting an absolute link, which is not very good when you transfer sites...

    November 30, 2014 at 10:54 am #133265
    alexadark
    Member

    Just found this plugin: https://wordpress.org/plugins/post-type-archive-links/
    🙂

  • Author
    Posts
Viewing 9 posts - 1 through 9 (of 9 total)
  • The forum ‘General Discussion’ 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