Forums

Tutorials and Guides for Adding Templates to Single Posts? (5 posts)

  1. Dirt2
    Member
    Posted 3 years ago #

    I am trying to mix up my blog a bit by having different types of posts instead of the usual text text text.

    I have installed this plugin: http://flutter.freshout.us/
    And it allows me to implement it into a template but I can't find any tutorials or information on how to achieve it.

    I downloaded a plugin but it ended up being something else, a prewritten post template for when I post.. I am looking for something that I can customize and select. I have created the page and stuck it in my templates section but I just can't figure out how to enable it.

    Sorry if I'm being confusing.
    A better understanding I guess is I have a resource/portfolio website and I want my vector posts, font posts etc. to all look different which is why the flutter plugin works but when they're displayed I want them look differently and there's no way to do this unless I can figure out how to do custom templates that I can choose from..

    Any help is appreciated.

  2. stvwlf
    Member
    Posted 3 years ago #

    Hi

    See if this is useful. This code would replace all the code in single.php. All other code in single.php gets placed in the custom single templates you will be creating.

    Unique Single template

    Suppose you want to use different Single template to display individual post in certain category. You can use the in_category to check what category is the post stored in and then use different Single template. In your default single.php, enter the code below. If the post is in category 1, use single1.php, elseif in category 2, use single2.php, otherwise use single_other.php.

    <?php
      $post = $wp_query- >post;
    
      if ( in_category('1') ) {
      include(TEMPLATEPATH . '/single1.php');
      } elseif ( in_category('2') ) {
      include(TEMPLATEPATH . '/single2.php');
      } else {
      include(TEMPLATEPATH . '/single_other.php');
      } ? >
  3. Dirt2
    Member
    Posted 3 years ago #

    Is that code possibly outdated?
    I tried it and I got an error saying Unexpected ">" on line 2 (where it obviously says >post)

    So I removed it and it doesn't do anything, I changed the first category to 72 (which is my fonts ID for my site) and I have it linked to fonts.php which I basically just copied and pasted my normal single.php except I added a bunch of text to it to tell if it was correct.

    I replaced my current single.php post with:

    <?php
      $post = $wp_query- post;
      if ( in_category('72') ) {
      include(TEMPLATEPATH . '/fonts.php');
      }  else {
      include(TEMPLATEPATH . '/single2.php');
      } ?>

    I should note that it does something, not sure what.
    Because there's no single.php so the else{ must be working.

    Thank you for the response nonetheless.

  4. stvwlf
    Member
    Posted 3 years ago #

    Hi

    I'm sorry, there was a typo in my original code, an extra space.

    this line
    $post = $wp_query- >post;
    should be
    $post = $wp_query->post;

    1) Yes, you must use category ID codes that exist on your site

    2)

    if ( in_category('1') ) {
      include(TEMPLATEPATH . '/single1.php');
      } elseif ( in_category('2') ) {
      include(TEMPLATEPATH . '/single2.php');
      } else {
      include(TEMPLATEPATH . '/single_other.php');
      } ? >

    In this code example, single_other.php becomes the default sidebar.

    To set this up, rename your theme's file single.php to the name of the new default file - in the example that is single_other.php (use whatever name you prefer).

    Make a new file in your theme folder called single.php - paste the code I posted in that new file. that is the only thing that should be in the new single.php.

    3) Make new files single1.php, single2.php, single3.php, setting them up however you wish as custom single templates.

    Give them whatever file name you want. Just change the name of the file for that category in the IF statement I posted to match the actual filename you give the file.

  5. Dirt2
    Member
    Posted 3 years ago #

    Great thanks that one small -> code changed everything!
    Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic