0

This is what I want: I have made a Custom Post Type in my theme and it shows in my home too, but the problem is that tha CPT takes the same elements and style of a default post in Wordpress, how I can assign a template for how my CPT is displayed at my home? When I say home I mean www.mysite.com (The content of index.php, this archive has the aspect of all the post in the home, so how I can create a dedicaded template to my CPT in the home)

Check this code example of a theme in index.php, but doesn't work for me:

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

                <?php

                if ( get_post_type() == 'reviews' ) : ?>

                    <?php include( TEMPLATEPATH . '/includes/show-reviews-frontpage.php' ); ?>

                <?php elseif ( get_post_type() == 'videos' ) : ?>

                    <?php include( TEMPLATEPATH . '/includes/show-videos-frontpage.php' ); ?>

                <?php elseif ( get_post_type() == 'screenshots' ) : ?>

                    <?php include( TEMPLATEPATH . '/includes/show-screenshots-frontpage.php' ); ?>

                <?php else: ?>

                    <?php include( TEMPLATEPATH . '/includes/show-posts-frontpage.php' ); ?>

                <?php endif; ?>

            <?php endwhile; ?>


            <?php endif; ?>

Thanks a lot.

4
  • 1
    I am not sure exactly what you are asking. Can you try to explain a bit better?
    – s_ha_dum
    Commented May 30, 2015 at 23:58
  • Let's assume that I have a Custom Post Type called 'Video' and I want custom templates for this CPT. I have single-video.php (The inside content - mysite.com/video/postname) video-archive.php (For display all my 'Video' posts in one page - mysite.com/videos), but I want a template for the way that is displayed in my home (mysite.com). I hope to be clear. Commented May 31, 2015 at 7:35
  • What have you done so far? Please post your work to date. Commented Jun 1, 2015 at 5:49
  • @BradDalton This is what I want: I have made a Custom Post Type in my theme and it shows in my home too, but the problem is that tha CPT takes the same elements and style of a default post in Wordpress, how I can assign a template for how my CPT is displayed at my home. When I say home I mean www.mysite.com (The content of index.php, this archive has the aspect of all the post in the home, so how I can create a dedicaded template to my CPT in the home) Check this code example of a theme, but doesn't work for me imagebam.com/image/433e05413060466 Commented Jun 1, 2015 at 14:40

3 Answers 3

0

I am thinking you probably want get_template_part() to load CPT specific pieces of code. For example (from the Codex):

get_template_part( 'nav', 'single' ); // Navigation bar to use in single pages (nav-single.php)

You can then reuse pieces of code on your home page, your CPT archives, etc.

You may also find post formats useful, though I am still unclear about exactly what you want to accomplish.

Take a look at the way Twenty Thirteen (for example), handles posts formats by using content-aside.php, content-audio.php, etc

4
  • I made an [image](www.imagebam.com/image/8b95ef412958801) to explain better. Commented May 31, 2015 at 21:05
  • The picture does not explain anything.
    – s_ha_dum
    Commented Jun 1, 2015 at 6:01
  • This is what I want: I have made a Custom Post Type in my theme and it shows in my home too, but the problem is that tha CPT takes the same elements and style of a default post in Wordpress, how I can assign a template for how my CPT is displayed at my home. When I say home I mean www.mysite.com (The content of index.php, this archive has the aspect of all the post in the home, so how I can create a dedicaded template to my CPT in the home) Check this code example of a theme, but doesn't work for me imagebam.com/image/433e05413060466 Commented Jun 1, 2015 at 14:37
  • No, that won't work, but using get_template_part() to load pieces of code to format your CPT content will.
    – s_ha_dum
    Commented Jun 1, 2015 at 14:51
1

There is only one home/frontpage, so I'm not sure, what are you trying to achieve...

Let's assume that your page is example.com and your CPT is books.

If you'd like to change the look of home/frontpage (the page you see when you go to example.com), then use one of these templates.

If you want to change the look of CPT index (the page you see when you go to example.com/books), then it is this CPT's archive template...

If you'd like to show books on home, then you should use pre_get_posts action to change main query for home...

3
  • Yeah, I want to change the look of the CPT in my home/frontpage, what template I should to use to edit that look? Commented May 31, 2015 at 7:39
  • Ehh, CPT is not displayed on home page by default... There is NO default template responsible for the look of CPT on home. Every option you could use is explained clearly in my answer. Commented May 31, 2015 at 9:54
  • This is what I want: I have made a Custom Post Type in my theme and it shows in my home too, but the problem is that tha CPT takes the same elements and style of a default post in Wordpress, how I can assign a template for how my CPT is displayed at my home. When I say home I mean www.mysite.com (The content of index.php, this archive has the aspect of all the post in the home, so how I can create a dedicaded template to my CPT in the home) Check this code example of a theme, but doesn't work for me imagebam.com/image/433e05413060466 Commented Jun 1, 2015 at 14:39
0

You can create a page template (refer this https://developer.wordpress.org/themes/basics/page-templates/ ). The page template code shall have a custom query to show the poats from your custom post type. Then create page named let's say 'Home'. Assign that page template to it. Then from 'Settings > Reading' Select static page to 'Home'.

3
  • Thanks for respond, but I want to change the look of a CPT when is displayed in my home (mysite.com), because for default wordpress assign the content and look of index.php to all the CPT. Commented May 31, 2015 at 8:11
  • To get different look you would certainly need to write custom css. Commented May 31, 2015 at 15:08
  • I made an image (www.imagebam.com/image/8b95ef412958801) to explain better. Commented May 31, 2015 at 21:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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