3

I find myself creating pages just as a "placeholder" to a listing page.

eg. I create a page "Blog" and "Portfolio". Both has the editor emtpy. And I just use it so that I can use page-blog.php and page-portfolio.php for the respective listing pages. It doesnt seem proper? Is there a better way?

2 Answers 2

5

I guess another way would be including 'has_archive' => true, into your register_post_type array and using archive-{posttype}.php to style your custom post type listings

1

I only use 'placeholder' pages if I'm listing just a few custom post types with no pagination (or any other miscellaneous data for that fact), so that the end user still has control over the things like the title & content (which you can use for introductory text and so forth).

It also has the advantage of getting listed in wp_list_pages(), which is handy if you're using it for navigation elsewhere in your theme.

However, as @Daniel said, if you want to make benefit of a full-blown archive with pagination & feeds, opt for the has_archive arg.

I tend to use a different slug for the archive as opposed to the single post, just for clarity.

So for example;

http://example.com/product/my-single-product/

And for archives;

http://example.com/products/

http://example.com/products/page/2

http://example.com/products/feed/

The code for it?

register_post_type( array(
    'rewrite' => array(
        'slug' => 'product', // defaults to post type name
        'with_front' => true, // prepends slug to single posts, default true
        'pages' => true, // support pagination, default true
        'feeds' => true // support feeds, default matches 'has_archive'
     ),

     'has_archive' => 'products' // if bool true, defaults to rewrite slug
) );
2
  • technically you can paginate a page containing posts, it's just a bit manual.
    – Milo
    Jun 15, 2011 at 15:53
  • Of course, but at that stage you'd need a very specific reason not to use the has_archive arg. Jun 15, 2011 at 16:08

Your Answer

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

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