Tagged: advanced custom fields
-
AuthorPosts
-
August 29, 2019 at 4:18 pm #1131951
Hi,
I’m trying to create a custom template for a specific post in my blog.
I’ve copied the single.php, renamed it (placed the template name on top), saved it into my child theme main folder, and I’ve copied the “includes” folder , with loop-index.php in it, into the same directory.
I’ve not made any change to those files yet (I’ve only added the template name comment), so I expect to see the new template into the post options, but it doesn’t show up. I’ve also disabled the ALB, but I can’t still see it.Can you please tell me if I did everything correct?
Best regards
Luca
August 29, 2019 at 7:55 pm #1132057Hey viaggiareverde,
Did you make any changes in the single.php file? What do you expect to show up?
Can you give us temporary admin access to your website in the private content box below, so that we can have a closer look?
Best regards,
VictoriaAugust 29, 2019 at 8:38 pm #1132078Hi,
No changes yet. I expect that the template shows up in the attributes section of the post editor.
And I’ve tried the same method with a custom template for pages, and it works.
But with the post template, I can’t even see the option where you can select between the default template and custom ones.Thanks for you help
August 30, 2019 at 10:07 am #1132240Hi viaggiareverde,
Can you please share the login link as well?
Best regards,
VictoriaAugust 30, 2019 at 10:40 am #1132266September 2, 2019 at 7:07 pm #1133099September 3, 2019 at 12:46 pm #1133343Hi,
Thank you for the update.
Did you specify the custom post type support after the Template Name?
* Template Post Type: post, page, product
Best regards,
IsmaelSeptember 18, 2019 at 10:27 pm #1139730Hi Ismael,
thanks a lot for your answer! That was the part that I missed, and now I can see and use the custom template I created.I have another question and maybe you can help me also with this.
I created that template to show posts from a custom post type (called “regali”), created with CPT UI.
I’m also using Advanced Custom Fields to add custom fields to that post type, and I’d like to display my custom fields inside the template.I’ve already checked lots of old topics about the use of ACF in Enfold, but I couldn’t find an answer that works for me, so I hope you can help me (I know that this goes a little beyond Enfold support, but I used ACF before but now I’m not able to make it work on Enfold)
So here is the code that I’ve added to my template, called “single-regali.php” (before and after this code there is the “default” code of enfold “single.php”):
<main class='content units <?php avia_layout_class( 'content' ); ?> <?php echo avia_blog_class_string(); ?>' <?php avia_markup_helper(array('context' => 'content','post_type'=>'post'));?>> <?php /* MY CODE ___________________________________________ */ $args = array ( 'post_type' => 'regali', ); $query = new WP_Query( $args); ?> <?php if ( $query->have_posts() ) : while( $query->have_posts() ) : $query->the_post(); ?> <!-- this is just a test --> <p> <?php echo date("Y"); ?> </p> <!-- here is the CPT --> <!-- title --> <h2> <?php get_field("oggetto"); ?> </h2> <!-- description --> <p> <?php get_field("descrizione"); ?> </p> <?php endwhile; endif; wp_reset_postdata(); ?> <!--end content--> </main>
Please notice that I’ve disabled ALB and that I’ve double checked both the names of the CPT and the ACF fields names along with ACF documentation.
Hope to hear from you soon!
Best regards
Luca
- This reply was modified 5 years, 3 months ago by viaggiareverde.
September 20, 2019 at 4:16 am #1140088Hi,
You should probably place echo before the get_field function. The get_field function doesn’t render the data in the template automatically.
Thank you for the update.
Best regards,
IsmaelSeptember 20, 2019 at 6:53 pm #1140310Hi Ismael,
thanks again, it solves the problem, I confused “the_field” with “get_field”…I really appreciate your helpful support.
Best regards
Luca
September 20, 2019 at 8:54 pm #1140334Hi,
I’m glad this was resolved. If you need additional help, please let us know here in the forums.
Best regards,
Jordan Shannon -
AuthorPosts
- The topic ‘Custom Template for Posts’ is closed to new replies.