• 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 create my own single-(post-type).php files ?

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 create my own single-(post-type).php files ?

This topic is: not resolved

Tagged: ACF, single-(post-type).php

  • This topic has 11 replies, 3 voices, and was last updated 9 years, 3 months ago by Guinnessboy.
Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • March 30, 2017 at 12:44 am #204032
    Guinnessboy
    Member

    Hi there,
    Newbie with Genesis i need to create my own single-(post-type).php template to display custom-post and ACF fields.

    Genesis sample single.php only contain the genesis() function.

    I don't understand how to create my own template and insert my own code and design. Can i use a 'classical' WP single.php ?

    Somebody can send a sample single-(post-type).php ? that will help me to understand how it works.

    Thanks for your help.

    March 30, 2017 at 1:10 am #204035
    Brad Dalton
    Participant

    This is all you need to get started.

    Use the WordPress Template Hierarchy to name the file like single-cpt.php where cpt is the name of your custom post type.

    Then add the code for your custom fields to the file.


    Tutorials for StudioPress Themes.

    March 30, 2017 at 5:10 am #204039
    Guinnessboy
    Member

    Hi Brad and thanks,

    I'm ok with WP template hierarchy and CPT.

    I don't know how to paste my code. Before the genesis() function ?

    //* Remove site footer widgets
    remove_action( 'genesis_before_footer', 'genesis_footer_widget_areas' );
    
    //* MY CODE HERE ????
    
    //* Run the Genesis loop
    genesis();
    
    March 30, 2017 at 5:24 am #204043
    Victor Font
    Moderator

    Yes, all of your code goes before the genesis function.


    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

    March 30, 2017 at 6:07 am #204047
    Guinnessboy
    Member

    Many thanks,

    It's getting better. fields are displayed not exactly at the right place. 🙂
    I still miss something.

    The problem

    my single-restaurant.php file content

    
    add_filter( 'body_class', 'single_posts_body_class' );
    function single_posts_body_class( $classes ) {
       $classes[] = 'custom-restaurant';
       return $classes;   
    }
    add_filter( 'genesis_site_layout', '__genesis_return_content_sidebar' );
    remove_action( 'genesis_before_footer', 'genesis_footer_widget_areas' );
    ?>
    
    <div id="resto-content">
    <p><?php the_field('resto-adresse'); ?></p>
    <img src="<?php the_field('resto-logo'); ?>" alt="" />
    </div>
    
    <?php
    add_action( 'genesis_before_footer', 'genesis_footer_widget_areas' );	
    genesis();
    
    March 30, 2017 at 7:33 am #204054
    Victor Font
    Moderator

    The fields are being displayed before the loop is run. The loop is called in the genesis function. You have to hook the custom fields into the content area. I would try genesis_entry_header or genesis_entry_content.


    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

    March 30, 2017 at 8:30 am #204057
    Guinnessboy
    Member

    Thanks Victor. I have to read all hook contents tutorials.
    I'm not familiar with this.
    I'll certainly be back later. 😉

    March 30, 2017 at 9:12 am #204058
    Guinnessboy
    Member

    I think i get it.
    Many thanks guys.

    The result

    
    //* Add  custom content
    add_action( 'genesis_entry_content', 'restaurant_entry_content' );
    function restaurant_entry_content() {
    	?>
    <div id="resto-content">
    <p><?php the_field('resto-adresse'); ?></p>
    <img src="<?php the_field('resto-logo'); ?>" alt="" />
    </div>
    	<?php
    }
    

    Now at work.

    Best regards,

    March 30, 2017 at 3:05 pm #204073
    Brad Dalton
    Participant

    I would also use get_post_meta rather than the_field.

    If your plugin deactivates, you lose the display of your content on the front end.


    Tutorials for StudioPress Themes.

    March 31, 2017 at 9:40 am #204118
    Guinnessboy
    Member

    Thx Brad,

    the_field is a function to get. You mean that i can get the same result using get_post_meta('act_field_name') ? ACF data are stored in the post-meta table ?

    I don't know how i can remove the date and author under the title.
    I tried to remove genesis_entry_header with no effects.

    March 31, 2017 at 2:21 pm #204132
    Brad Dalton
    Participant

    You could use:

    get_post_meta('get_the_ID(),'resto-adresse', true);
    get_post_meta('get_the_ID(),'resto-logo', true);
    

    genesis_entry_header is the hook you use to output the custom field data in a specific position on a page.


    Tutorials for StudioPress Themes.

    April 4, 2017 at 6:59 am #204269
    Guinnessboy
    Member

    Thanks Brad. I'll will check that.
    I'm on the right way with.
    But still a lot of work.

  • Author
    Posts
Viewing 12 posts - 1 through 12 (of 12 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

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