How to make custom template for custom post type

Hello,

I am in desperate need of help to fix this problem:

I have a custom post type, that I want to create a custom post template for, that I have FULL control over.

Right now I have created a single-{custom-post-type}.php file and pasted the following code:

<?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(); ?>>
       MY CUSTOM CONTENT GOES HERE
      </article>

    <?php endwhile; ?>

  </div>

<?php get_footer(); ?>

But when I do this it still displays the blog-header. So my question is, how can I create my own custom template for my custom post type?

I have tried to follow this thread:

But it is too difficult for me to understand.

I am looking very much forward to your help. If this problem persists it is unfortuantely a reason to switch theme:(

Hello There,

Thanks for writing in! If you do not want to display the default header, you can remove this line of code:

<?php get_header(); ?>

And replace it with this:

<?php

$x_root_atts = x_atts( apply_filters( 'x_root_atts', array( 'id' => 'x-root', 'class' => 'x-root' ) ) );
$x_site_atts = x_atts( apply_filters( 'x_site_atts', array( 'id' => 'x-site', 'class' => 'x-site site' ) ) );

?>

<!DOCTYPE html>

<html class="no-js" <?php language_attributes(); ?>>

<head>
  <?php wp_head(); ?>
</head>

<body <?php body_class(); ?>>

  <div <?php echo $x_root_atts; ?>>

    <?php do_action( 'x_before_site_begin' ); ?>

    <div <?php echo $x_site_atts; ?>>

    <?php do_action( 'x_after_site_begin' ); ?>

Please let us know if this works out for you.

Did you not just copy the content from the base.php file from the header folder?

How would that solve my problem? My question is VERY simple: how do I create a custom template for my custom post type?

Hi There,

There must be a misunderstanding. From your initial message, it was assumed you have added the template already and just want to remove the default header. That is the reason behind previous reply. Since this is not the case, please clarify what you have done so far and which part is not working as expected. What file have you create on what folder and what’s the content. What’s the URL of this custom post type too? This will help up understand where the issue is.

Yes, as I have mentioned I have created the single-{custom-post-type}.php. And as I already said that method is NOT working for me. The reason it is not working is because when i go to my custom post type it still shows the “the blog” header below the normal header (the following image is from an ordinary post but just to clarify which header i am talking about).

I do NOT want to have the “the blog” header just above the post shown in my custom template.

So I need a solution on how to, as I have said, create a custom template for my custom post type? It is really that simple.

Hi,

We can hide it using css.

You can add the code below in X > Launch > Options > CSS

.single-events .x-header-landmark {
    display:none;
}

Hope that helps.

Seriously guys.
my question is: HOW DO I CREATE A CUSTOM TEMPLATE FOR MY CUSTOM POST TYPE. Sorry for using caps, but in no way does your response answer that question, which i have repeated a number of times now - even the topic title says it. So forget everything else I have written so far, that seems to confuse you.

Thanks.

Hi,

You were right in creating single-{custom-post-type}.php file and as I have read the remaining problem is the Blog Header.

The Blog Header code is located in x/framework/legacy/cranium/headers/views/integrity/_landmark-header.php

If you check that file, there is a lot of code in there, so instead of adding it to your child theme and modfying that code I provided you with a simple css code that will still cater your needs(remove blog header).

.single-events .x-header-landmark {
    display:none;
}

You may change single-events with your custom post type.

Please provide us your site url. This is to ensure that we can provide you with a tailored answer to your situation.

Thank you.

Hey @Jell92 how’s it hanging my dude.

I was recently trying to figure out the same thing and the X structure was throwing me for a spin.

Pretty much what i did was make a single-{custom-post-type}.php file. Then copied the contents from wp-single-x-portfolio.php and modified it according to how i want the content to output. Make sure you put this file in the root of your child-theme directory.

With some HTML, CSS, JS you can make your dreams come true for your page.

I followed WordPress best practices for creating the custsom post type template.

Check out my code for reference. I used ACF so anything with ( the_field(); ) is calling an ACF field.

Notice at the top I added Template Name & Template Post Type this pulls the template file to the specified post type in my case “events” is my CPT.

<?php

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

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

?>

<?php get_header(); ?>

<div class="x-main full" role="main">
    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
        <?php while ( have_posts() ) : the_post(); ?>
        <div class="entry-wrap">
            <div class="x-container max width">
            <!-- Event Title -->
            <header class="entry-header">
                <h1><?php the_title(); ?></h1>
            </header>
            <div class="event-date">
                <?php the_field('date'); ?> from <?php the_field('start_time'); ?> to <?php the_field('end_time'); ?>
                <?php echo $location['address']; ?>
            </div>
            <!-- Event Title end -->
            <!-- Entry Image Full Width-->
            <div class="event-image">
                <?php if( $thumbnail ): ?>
                    <img class="text-center" src="<?php echo $thumbnail['url']; ?>" alt="<?php echo $thumbnail['alt']; ?>" />
                <?php endif; ?>
            </div>
            <!-- Entry Image  -->

            <!-- Event Details -->
            <div class="event-details">
                <h2>About The Event:</h2>
                <?php the_content(); ?>
                <?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>
            
            <!-- Event Details end -->
            </div>
        </div>
        <?php endwhile; ?>
    </article>
</div>

<?php get_footer(); ?>

hope this helps my good man!!

Thanks for the replies.

I think I have solved it myself, but I will take a close look at your answer Vcitor2:)

Paul.r:
Actually my solution was to add an if statement in the landmark-header.php in my child theme, that checks if the post is of my custom type. But in your reply it sounds like that is a bad solution? Or is it OK to do it like that?

Hi There,

Thanks for sharing your solution you are good to go

Thanks!