Post Template for Custom Post Type

Hello

I am having an issue with creating a post template for an “events” custom post type i have created.

I am using ACF to additional fields for the event information and have my child-theme set up and activated.

I have copied the wp-single.php file over to pro-child/views/icon/ and made modifications according to the documentation on ACF’s site.

It seems like wordpress is ignoring the template.

you can see the post page here.

https://staging.warmdocs.com/wp/events/test/

<?php

// =============================================================================
/*
 * Template Name: Event Article
 * Template Post Type: events
 */
// -----------------------------------------------------------------------------
// VIEWS/ICON/WP-SINGLE.PHP
// -----------------------------------------------------------------------------
// Single post output for Icon.
// =============================================================================

$fullwidth = get_post_meta( get_the_ID(), '_x_post_layout', true );

// vars
$location = get_field('location');
$thumbnail = get_field('event_image');

?>

<?php get_header(); ?>
  
  <div class="x-main full" role="main">

    <?php while ( have_posts() ) : the_post(); ?>
    <div id="event-hero">
		
		<?php if( $location ): ?>
		<div id="event-map" class="acf-map">
			<div class="marker" data-lat="<?php echo $location['lat']; ?>" data-lng="<?php echo $location['lng']; ?>"></div>
		</div>
		<?php endif; ?>
		
		
		<?php if( $thumbnail ): ?>
			<img class="thumbnail" src="<?php echo $thumbnail['url']; ?>" alt="<?php echo $thumbnail['alt']; ?>" />
		<?php endif; ?>
		
		<h2><?php the_title(); ?></h2>
		<h3><?php the_field('date'); ?> from <?php the_field('start_time'); ?> to <?php the_field('end_time'); ?></h3>
		<h4><?php echo $location['address']; ?></h4>
		
	</div>
      <?php x_get_view( 'icon', 'content', get_post_format() ); ?>
      <?php x_get_view( 'global', '_comments-template' ); ?>
    <?php endwhile; ?>

  </div>

  <?php if ( $fullwidth != 'on' ) : ?>
    <?php get_sidebar(); ?>
  <?php endif; ?>
<?php get_footer(); ?>

Hi There,

It’s best to follow wordpress template heirarchy https://codex.wordpress.org/Template_Hierarchy and X theme customization best practices https://theme.co/apex/forum/t/customizations-best-practices/205

There is no selectable template for post, it’s not the same as page. But, each post type has their own corresponding template. single.php is default template for post regardless of type, but you can always create your own post type template such as single-x-portfolio.php, single-event.php and etc.

About post format, it’s simply controlled by get_template_parts() https://codex.wordpress.org/Function_Reference/get_template_part and you can call a post format template like this.

Portfolio is a custom post type. Check how templates work on single-x-portfolio.php for guidance.

Hello @Lely

I have successfully created a template for my custom post type “events” and have the ACF fields displaying properly.

I want to add a sidebar to the custom post type but am having trouble.

If you check ( https://staging.warmdocs.com/wp/events/test/ ) you can see the sidebar i have created at the bottom of the page next to the footer.

Any help or advice is appreciated.

This is my current code setup

<?php

/*
Template Name: Event Info
Template Post Type: events
*/

// vars
$location = get_field('location');
$thumbnail = get_field('event_image');

?>

<?php get_header(); ?>

<div class="x-main full" role="main">
<?php while ( have_posts() ) : the_post(); ?>

    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
        <div class="entry-wrap">

        <div class="x-container max width">

        <?php if( $location ): ?>
		<div id="event-map" class="acf-map">
			<div class="marker" data-lat="<?php echo $location['lat']; ?>" data-lng="<?php echo $location['lng']; ?>"></div>
		</div>
		<?php endif; ?>
        
        <div>
        <header class="entry-header">
            <h1 class="entry-title"><?php the_title(); ?></h1>
        </header>
        <?php if( $thumbnail ): ?>
			<img class="thumbnail" src="<?php echo $thumbnail['url']; ?>" alt="<?php echo $thumbnail['alt']; ?>" />
		<?php endif; ?>
        </div>

        <?php the_field('date'); ?> from <?php the_field('start_time'); ?> to <?php the_field('end_time'); ?>
		<?php echo $location['address']; ?>

        <?php the_content(); ?>

        
       <?php gravity_form( 1, false, false, false, '', false ); ?>



        <?php if ( is_singular() ) : ?>

        <div class="entry-extra">
          <?php x_portfolio_item_tags(); ?>
          <?php x_portfolio_item_project_link(); ?>
          <?php x_portfolio_item_social(); ?>
        </div>

      <?php endif; ?>

        </div>
        </div>
    </article>

    <?php endwhile; ?>

</div>

<?php get_sidebar(); ?>
<?php get_footer(); ?>

Hi There,

Glad you have sorted out custom templates for this custom post type. Regarding sidebar, this template is still set to fullwidth. From the code you have share, look for this line:

<div class="x-main full" role="main">

Update to this:

    <div class="x-container max width offset"> 
    <div class="x-main left" role="main">

See how full is replace by left class so content is on the left. Then I have put it inside a container.
Now we need to add the closing of that container after the right sidebar.
Look for this part:

</div>

<?php get_sidebar(); ?>

Update to this:

</div> // This is the closing of left content container.

<?php get_sidebar(); ?>
</div> // This is the closing of the container that I have added on top of the  left container. This will enclose both left and right content in a just one container.

Hope this helps.