Using Seperate Templates

Hi there,

Site: https://fantasy-books.live
Wordpress: 4.9.7
X Pro: recent.

Problem:

I would like to change the post template. Currently, I am updating. wp-single.php. But that has it’s problems.

It automatically ads to page templates as well.

But I don’t want to make a seperate template and have to manually set the template on every post creation.

Is there a way to:

  1. Make a post template and set it as default for posts?

  2. Make a page template and set it as default for pages?

etc… even custom post types.

If not, do you have any suggestions? Maybe not using wp-singe.php and use something else?

Hi @JfantasyBooks,

Thanks for writing in.

What changes you’re adding to wp-single.php? It’s for the post and wp-page.php is for the page. The change to a specific template shouldn’t affect each other.

And for custom post types inheriting the post type will automatically use wp-single.php, then a custom post type inheriting the page type will automatically use wp-page.php.

Post type has default single.php and it’s decided by Wordpress, so the page.php and you can’t change that unless you’ll add a custom code that will redirect the template and it’s something we don’t support.

Please provide the problems and its details with wp-single.php and we’ll check.

Thanks!

Oh, I made a mistake, I was on a post and saw it.

Anyways, the problem is I want to default templates by custom post type.

That way, I don’t have to manually add the template via admin panel every time. I have a lot of authors, and they are bound to make mistakes.

If you have any advice, I’d appreciate it.

Thanks

j.

Hi There,

Please setup a child theme first: https://theme.co/apex/forum/t/setup-how-to-setup-child-themes/57

After that create this file in your child theme directory: single-{slug}.php with the following code:

<?php

// =============================================================================
// VIEWS/INTEGRITY/WP-SINGLE.PHP
// -----------------------------------------------------------------------------
// Single post output for Integrity.
// =============================================================================

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

get_header();

?>

  <div class="x-container max width offset">
    <div class="<?php x_main_content_class(); ?>" role="main">

      <?php while ( have_posts() ) : the_post(); ?>
        <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
          <div class="entry-featured">
            <?php x_featured_image(); ?>
          </div>
          <div class="entry-wrap">
            <?php x_get_view( 'global', '_content' ); ?>
          </div>
        </article>
        <?php x_get_view( 'global', '_comments-template' ); ?>
      <?php endwhile; ?>

    </div>

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

  </div>

<?php get_footer(); ?>

You have to replace the {slug} with your custom post type slug.

For more information, please take a look at this: https://developer.wordpress.org/themes/basics/template-hierarchy/#custom-post-types.

Hope it helps :slight_smile:

Hi. Where exactly in the theme folder? Because it is not working. It still uses the wp-single.php

Nvm. It works! Thanks

Glad that we could be of a help :slight_smile:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.