Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialLiam Maclachlan
22,805 PointsCan you over use custom post types?
I'm using custom post types for alot at the moment. For all the relevant things it is meant to be used for, But I'm also using them to populate sliding banners (in hand with Twitter Bootstrap) and restricting what shows up on certain pages using the categories effectively.
Is that overkill, or am I just keeping things maintainable?
Just in case you are intrested, this is the code I'm using in hand with custom post types for displaying items on the homepage.
<div id="myCarousel2" class="carousel slide" data-ride="myCarousel2" data-interval="6000">
<div class="carousel-inner-two" role="listbox">
<!-- Start Bootstrap slider here -->
<!-- count for data-slide-to etc -->
<?php $count = 0;?>
<!-- custom args for page -->
<?php $args = array('post_type' => 'slider', 'category_name' => 'home'); ?>
<?php $query = new WP_query($args); ?>
<?php if( $query->have_posts() ): while ( $query->have_posts() ) : $query->the_post(); //starts loop through top level repeater field for loop ?>
<!-- adds textured images that is uploaded on the backend as full width background image -->
<div class="item <?php if ( $count == 0 ) echo 'active'; ?>" style="background: url(<?php the_field('background');?>) no-repeat center / 100% auto;">
<!-- Displays clickable CTA's on the banner -->
<div class="max-width banner__content">
<h2 style="margin-bottom: 0;"><?php the_title(); ?></h2>
<?php the_content();?>
</div>
</div>
<?php $count++; ?>
<?php endwhile; else: ?>
<p>No information available</p>
<?php endif;?>
<?php wp_reset_postdata(); ?>
</div>
</div>
2 Answers
Liam Maclachlan
22,805 PointsOkay. As commented, this is my solutions. Set up the page ('single-slider.php') and only have this code in the template:
<?php
header( 'location:' . home_url() );
?>
This is to avoid anyone typing in the url (even accidentally) and will redirect them to the main page and avoid any unecessary template mark up.
If anyone has another suggestion, including alternatives to using CPTs, keep posting and I'll happily accept another answer :)
Colin Marshall
32,861 PointsIn my opinion you should be using custom post types to logically differentiate between different types of data in a way that makes sense for the business. As long as you do that and keep the dashboard organized in a way that all back-end users can understand and easily navigate, then you are fine.
Liam Maclachlan
22,805 PointsThat was my thinking...but... these are generating pages where people can access, using the index,php template. That makes me think it is not the best idea, and not in line with bext practice
Colin Marshall
32,861 PointsIt's perfectly fine. When I was talking about the back-end I just meant creating/editing the custom post type content. Custom post type content in almost all situations will be displayed on the front-end.
Liam Maclachlan
22,805 PointsYeah... It just feels wrong. Knowing that if you type in the slug really bothers me. It will bring up the ulta-fallback, index.php page to display the content... Very annoying... Not unless I set up a single.php for these pages and set it up to redirect to the home page, just incase it is found.
Untill I concuct another way of doing this, I think that will have to do :)
Liam Maclachlan
22,805 PointsYeah. This worked nicely.
The template for single-slider.php is
<?php
header( 'location:'.home_url() );
?>
Win
Colin Marshall
32,861 PointsColin Marshall
32,861 PointsThat's a good solution. Maybe Zac Gordon has something to offer here.
Liam Maclachlan
22,805 PointsLiam Maclachlan
22,805 PointsThanks man. Appreciated :)
Liam Maclachlan
22,805 PointsLiam Maclachlan
22,805 PointsColin. Just found this, man. Very useful when it comes to the SEO side of the custom post type. The site map structure to avoid the Slider type showing in Search engines is about 4:50 in to the video .
https://teamtreehouse.com/library/seo-for-wordpress/seo-plugins-for-wordpress/the-wordpress-seo-plugin-from-yoast