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.

I currently have a new custom post type-- "Books." I have a custom rewrite url that I set when registering my post type:

'rewrite' => array( 'slug' => 'books', 'with_front' => false )

It works great when I visit a specific post, but how do I take control of the /books url for displaying a list of ALL of the books by date posted?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Once way of doing it - I am sure there are other ways too - is to make a page template for books: books.php You can make a copy of page.php and rename it. In the top of the file you place the usual Page Template code as in:

<?php
/* 
Template Name: Books
*/
get_header(); ?>

Below the normal loop, you then place the code for a new loop:

<?php $loop = new WP_Query( array( 'post_type' => 'books') ); ?>
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>

Don't forget to close it with the call for <?php endwhile; ?> at the end.

With this method you can within WordPress add a Page called Books and assign this particular Template to it. This way you can still add general text to the page too and below display the list of all books.

share|improve this answer
    
Interesting solution-- never would have thought of using pages like that. In my case, this will work just fine :) –  Andrew M Jun 19 '11 at 16:10

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.