Community Forums › Forums › Archived Forums › Design Tips and Tricks › How to create my own single-(post-type).php files ?
Tagged: ACF, single-(post-type).php
- This topic has 11 replies, 3 voices, and was last updated 6 years, 12 months ago by Guinnessboy.
-
AuthorPosts
-
March 30, 2017 at 12:44 am #204032GuinnessboyMember
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 #204035Brad DaltonParticipantThis 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.
March 30, 2017 at 5:10 am #204039GuinnessboyMemberHi 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 #204043Victor FontModeratorYes, 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 #204047GuinnessboyMemberMany thanks,
It's getting better. fields are displayed not exactly at the right place. 🙂
I still miss something.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 #204054Victor FontModeratorThe 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 #204057GuinnessboyMemberThanks 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 #204058GuinnessboyMemberI think i get it.
Many thanks guys.//* 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 #204073Brad DaltonParticipantI 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.
March 31, 2017 at 9:40 am #204118GuinnessboyMemberThx 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 #204132Brad DaltonParticipantYou 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.
April 4, 2017 at 6:59 am #204269GuinnessboyMemberThanks Brad. I'll will check that.
I'm on the right way with.
But still a lot of work. -
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.