Jump to content


Photo
- - - - -

Custom post templates


This topic has been archived. This means that you cannot reply to this topic.
8 replies to this topic

#1 dcrosby

dcrosby

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 07 October 2010 - 04:59 PM

Hi folks, i thought I submitted this question earlier but don't see it now. Apologies if it shows up twice. I'm interested in creating custom post templates to replace the standard "single.php" file for certain categories. In the past I've used a plug-in such as "Custom Post Template". I'd dupe the original "single.php", rename and make changes, then choose it from a dropdown on post admin page. In your WhiteHouse Pro theme "single.php" calls "template_posts.php", which then calls "_posts" so it appears I'd have to change three files to get the desired result. Can I create custom posts more effeciently using the "custom post type" function? Could the post type be linked to a category so there is not another dropdown needing attention? I've seen some info about how to call a "custom post type" but not on how to actually assign it to individual posts. I'd probably want to do the same with sidebars as well. Can anyone lead me in the right direction?

#2 cmunns

cmunns

    Advocate

  • Members

  • 6537 posts

Posted 07 October 2010 - 09:45 PM

Darryl,

I'm not sure what place your at but this will definitely help clear things up...

Please Login or Register to see this Hidden Content



It's a terrific article.

_posts should be the only file you really need to edit if you want to only change what's inside the loop or main content area.

Let me know if you still need clarification.

#3 dcrosby

dcrosby

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 08 October 2010 - 02:03 PM

cmunns,

That article did give me a better understanding of how custom post types are used. I'd have to look it over more closely to see if I'm up to that challange.

At the end of the day though it came down to this:

default custom post types will display using

Please Login or Register to see this Hidden Content

, or

Please Login or Register to see this Hidden Content

as a fallback. The great thing is we can create our own custom template using the filename

Please Login or Register to see this Hidden Content


When i look at Whitehouse Pro's

Please Login or Register to see this Hidden Content

file it looks like this
`
get_header();
get_template_part('library/template_posts');
get_footer();
?>
`
rather than a

Please Login or Register to see this Hidden Content

file that i'm familiar with, such as the one in the twentyten theme.

I've been making modifications to the loop using custom fields in the

Please Login or Register to see this Hidden Content

but those changes will be universal. I need to have three different kinds/layouts of posts and ultimately three different kinds/layouts of archives.

I guess I'm having trouble understanding your structure compared to the simpler themes I'm familiar with.

thanks

#4 cmunns

cmunns

    Advocate

  • Members

  • 6537 posts

Posted 08 October 2010 - 05:12 PM

template_posts will control most of the structure outside of the loop e.g. sets fullwidth variable, and so forth...Likely that is what you'll want to modify then for layout changes. We use one file to control the loop and one file (template_posts) to control layout so when everything can be changed once instead of multiple times on single, archive, category, etc templates. Conditionals rule and we use them a lot as you'll see. If you can describe a little more of what you're desired effect is a can provide more guidance but that is the basic structure.

#5 dcrosby

dcrosby

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 08 October 2010 - 06:18 PM

Yes, I do see that conditionals are used quite a bit. I assume those are to allow users to customize their pages easily through the admin panel rather than having to dig into the code, yes? I'm putting together a site or a book publisher. Each book is a post with its series or subject as a category. I also want to use posts for a regular blog and for news stories. I need the end user to be able to input the book's data into custom fields so it shows on the post in the proper style and orientation. For instance, I have a field for the subtitle that shows up beneath the title in a smaller font. I've also removed the post date and would like to move the category and author info to another part of the page. For a post under the news category though, I may want to keep the post date, omit the author and perhaps change the title font. Plus the sidebar might show just the archives for news. This is where I add the obligatory "I'm a PHP noob but willing to learn" disclaimer. I'm becoming more clear on the structure but not on the code. I thought I could simply create different layouts and apply them on a post by post basis, same with archives. Might not be very elegant but fairly understandable. I'm willing to explore a better way though. thanks again

#6 cmunns

cmunns

    Advocate

  • Members

  • 6537 posts

Posted 11 October 2010 - 05:45 PM

You could create the necessary formatting by using custom fields for all the posts, so they are only inserted when used. Special formatting even can be done with a conditional if you know want to remove/add content all inside the _posts.php Adding your own for a category type would be something like ` HTML GOES HERE ` where 4 is the category ID...If your new to PHP I recommend practicing with conditionals first as they are very important. Then try and get the custom post type setup.

#7 dcrosby

dcrosby

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 12 October 2010 - 07:53 PM

Thought I'd try creating a custom post type as demonstrated in the thinkvitamin.com tutorial you linked to. I was able to create a custom post type but the admin area didn't include the "WhitehousePro Post Options", The "Custom Field Template" options from the plugin I'd installed, nor was I able to upload an image to the post (the featured image worked fine). The good news is that it did recognize the single-portfolio.php template file that I created for it (though you're suggesting I use conditionals to make my modifications). Any ideas on the issues mentioned?

#8 cmunns

cmunns

    Advocate

  • Members

  • 6537 posts

Posted 12 October 2010 - 11:51 PM

You don't have to use conditionals at all, i just thought it would be good practice...but you will have to link to the _posts.php file like it does in template_posts.php if you want to do it that way and show posts. I'm not clear on the first issue however, with the admin area?

#9 dcrosby

dcrosby

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 13 October 2010 - 09:46 PM

Your themes allow the admin to choose different page options for a post such as "default sidebar" or "short sidebar", or to add a "content sidebar," etc. Those options don't appear in my custom post type admin page. The options for Custom Field Templates that appeared when I installed the plugin of the same name don't appear in the admin area for this post type either (I see that the code I added to function.php adds custom field areas, the plugin is just easier). Basically my admin area looks exactly like the one in the tutorial you directed me to (it was helpful). Can I still use the options available in WhiteHousePro?