Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #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

    #1132057

    Hey 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,
    Victoria

    #1132078

    Hi,
    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

    #1132240

    Hi viaggiareverde,

    Can you please share the login link as well?

    Best regards,
    Victoria

    #1132266

    Sure.

    #1133099

    @Victoria, any news?
    Thanks

    Luca

    #1133343

    Hi,

    Thank you for the update.

    Did you specify the custom post type support after the Template Name?

    * Template Post Type: post, page, product
    

    // https://developer.wordpress.org/themes/template-files-section/page-template-files/#creating-page-templates-for-specific-post-types

    Best regards,
    Ismael

    #1139730

    Hi 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

    #1140088

    Hi,

    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,
    Ismael

    #1140310

    Hi Ismael,
    thanks again, it solves the problem, I confused “the_field” with “get_field”…

    I really appreciate your helpful support.

    Best regards

    Luca

    #1140334

    Hi,

    I’m glad this was resolved. If you need additional help, please let us know here in the forums.

    Best regards,
    Jordan Shannon

Viewing 11 posts - 1 through 11 (of 11 total)
  • The topic ‘Custom Template for Posts’ is closed to new replies.