WordPress archive page for multiple post types

If you want to make an archive page for multiple post types you want to show the title of the post type first. You can do that by using:

<?php post_type_archive_title(); ?>

http://codex.wordpress.org/Function_Reference/post_type_archive_title

For showing the content you can use the normal loop. But if you want to modify the loop by query_post(); you have to make a variable for ‘post_type’ that automatically fills in the right post type name.

You can do that by using the get_queried_object(); function:

http://codex.wordpress.org/Function_Reference/get_queried_object

As follows:

<?php
$obj = get_queried_object();
$post_type = $obj->name;
$args = array(
  'post_type' => $post_type,
  'orderby' => 'title',
  'order' => 'ASC',
  'posts_per_page' => 20,
 );
query_posts($args);
// And then the loop
?>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s