Just downloaded roots and so far so good…
However I have a question regarding custom post types. I created a new post type “Auction” in lib/custom.php by using this code
add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'auction',
array(
'labels' => array(
'name' => __( 'Auctions' ),
'singular_name' => __( 'Auction' )
),
'public' => true,
'has_archive' => true,
'slug' => 'auction',
'with_front' => false
)
);
}
add_filter('roots_wrap_base', 'roots_wrap_base_cpts'); // Add our function to the roots_wrap_base filter
function roots_wrap_base_cpts($templates) {
$cpt = get_post_type(); // Get the current post type
if ($cpt) {
array_unshift($templates, 'base-' . $cpt . '.php'); // Shift the template to the front of the array
}
return $templates; // Return our modified array with base-$cpt.php at the front of the queue
}
Then I went to Settings > Reading and changed “Posts Page” to a page “News” which I created. I also changed the Permalink Structure to “/news/%postname%/
This resulted in a correct structure for the default wordpress post type where I got ‘domain.com/news/’ as the listing page and ‘domain.com/news/hello-world’ as my single page. However I have a problem with my custom post type as now I need to go to ‘domain.com/news/auction/’ to see all the auction entries and ‘domain.com/news/auction/auction-1’ to access the single auction. I am aiming to get to ‘domain.com/auctions/’ whilst still keeping the custom structure for the default wordpress post type.
I though that setting the custom post type to ‘with_front’ as false would avoid this. Am I missing something that is specific to roots.
Any help would be greatly appreciated.