Customize Single Post Template for Custom Post Type

This is a PRIVATE forum for verified users only, to view all replies/answers, you must be logged in!

Status: not resolved
Viewing 6 reply threads
  • Author
    Posts
    • #5430

      arddevil
      Member

      Hi,

      I have a custom post type with name “Products.” All the posts under this custom post type are working normally as a usual post. But I want to remove the sidebar from all the posts under this custom post type. I mean I want to display posts from “Products” in full width.

      So, how can I do that?

    • #5442

      Jacob
      Staff

      Hey there, You must be logged in to view this reply!

      Login | Register | Forgot Password?

    • #5476

      There are several ways this can be done. The YT framework sorta breaks the WP template inheritance model, but the easiest and most maintainable way I found was to create a proper template as expected by the WP method, then include it with any customizations I need using hooks.

      single-{post_type}.php:

      <?php
      /**
       * Template for custom post_type
       */
      // alter the theme options data before rendering the page
      add_filter( 'yt_before_return_theme_options_data', function ( $options ) {
        // overwrite the layout to full width rather than the configured option
        $options['layout'] = 'fullwidth';
        return $options;
      } );
      // include the parent template to render the page normally
      load_template( path_join( TEMPLATEPATH, 'single.php' ), true );

      http://codex.wordpress.org/Post_Type_Templates

    • #5506

      Max
      Staff

      Hey there, You must be logged in to view this reply!

      Login | Register | Forgot Password?

    • #5515

      Our framework doesn’t break the template inheritance model by WP, you folks still can use your custom template normally.

      Indeed it doesn’t actually break inheritance, hence the reason I very carefully chose the phrase “sorta breaks”, but many well-recognized conventions in the rest of the theme community are not observed and took me for a loop when first working with Sparkle.

      The common convention when working with post formats is to use the content-{post_format}.php templates for the differing formats, included from single.php:

      <?php get_template_part( 'content', get_post_format() ); ?>

      Which allows child themes to simply create content-{post_format}.php to override the different format type templates (alternatively format-{post_format}.php is often used as well).

      single.php
          |-> content-aside.php
          |-> content-gallery.php
          |-> content-image.php
          |-> content-audio.php
          \-> content.php

      Instead YT is doing this with an extremely unwieldy set of if/else statements in content.php for the archive pages, then using a similar but different method in content-single.php which make it rather difficult to customize different post format templates. Asking non-developer types to figure this out requires a lot of training.

    • #5551

      Jacob
      Staff

      Hey there, You must be logged in to view this reply!

      Login | Register | Forgot Password?

    • #5647

      @Jacob wrote:

      why don’t you overwrite template single.php and index.php?

      I don’t do this because I’d like to be able to upgrade the base theme and not have to rewrite my child theme from scratch every time a new version is released. Maintaining the differences for this method would become nightmarish fast.

      I know it’s possible, I just didn’t hunk it would be a smart solution given the structure of the theme currently.

Viewing 6 reply threads
  • You must be logged in to reply to this topic.

This is a PRIVATE forum for verified users only, to view all replies/answers, you must be logged in!

© Copyright 2021 by wpthms.com. All Rights Reserved.