Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

For example, I have post named "My book number 1", that is in "Book" custom post type group. And is another post named "My book number 2", that is too in "Book" custom post type.

Question: How I can set specific design template for "My book number 1" post?

share|improve this question
add comment

3 Answers

up vote 0 down vote accepted

You can just create a template...call it something like book-one-template.php, the first line after <?php will need to be /* Template Name: Book One Template */. Then, using that and the custom-post-template plugin you can set that as the template for any post you like.

share|improve this answer
    
ru.forums.wordpress.org/topic/… in custom-post-templates.php 71 line $post_types = apply_filters( 'cpt_post_types', array( 'post' ) ); we must add 'book' $post_types = apply_filters( 'cpt_post_types', array( 'post','book' ) ); –  Vital Jan 31 '12 at 11:19
add comment

One way of doing it would be as follows: using the name of the post to determine how it displays.

Firstly, open page.php and "Save As" it to single-book.php.

Secondly, find "the loop", i.e. where your page.php has its while... statement.

You can then use code similar to the following to differentiate styles between different books:

<?php while (have_posts()) : the_post(); ?>

    <?php global $post; ?>

    <?php if ( stristr($post->post_name, "Book 1") ) : ?>
    <?php /* do something for your first book here */

        <div class="post" id="post-<?php the_ID(); ?>">

        <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>

        <div class="entry">

        <?php the_content('Continue reading &raquo;'); ?>

        </div>

    <?php else if ( stristr($post->post_name, "Book 2") ) :  ?>
    <?php /* do something different for your second book */

        <div class="post" id="post-<?php the_ID(); ?>">

        <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>

        <div class="entry">

        <?php the_content('Continue reading &raquo;'); ?>

        </div>

    <?php else : ?>
    <?php /* do something different for the rest of the books... */

        <div class="post" id="post-<?php the_ID(); ?>">

        <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>

        <div class="entry">

        <?php the_content('Continue reading &raquo;'); ?>

        </div>

    <?php endif; ?>

<?php endwhile; ?>

The stristr PHP function checks to see if the second parameter (here string "Book 1") exists in the first parameter (here string $post->post_name). It also differentiates for "Book 2". Obviously you can add as many of those as you like and change the text accordingly.

share|improve this answer
    
Ok, thanks for this snippet of code ;) Not bad solution, at this time it is the best ;) –  Vital Jan 30 '12 at 15:42
add comment

Maybe this answer is helpful to you:

Created custom post type but selected template not staying selected

notice that you'll have to set foo_resources inside of the custom_template_redirect function to your custom post type

share|improve this answer
    
This not solving my problem, because it applying template for whole custom post group. –  Vital Jan 30 '12 at 14:26
    
I need apply template only for specific post of some custom post type. –  Vital Jan 30 '12 at 14:27
    
Actually it gives you the ability to chose which template to use on the post edit screen..like you may know it from standard "page" post type. You are aware of the way custom page templates work in WordPress? Maybe I just don't understand what you try to archive. –  ungestaltbar Jan 30 '12 at 15:14
    
Code snippet of "dunc" user, giving me ability to set specific template for "specific post " of some custom post type. (Not for all posts, but for individual one) ;) –  Vital Jan 30 '12 at 16:14
    
When Im trying to work with your code, it applies page template for all posts that are in "Book" custom post type. –  Vital Jan 30 '12 at 16:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.