WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I created a custom post type "landing_page" to hold content I want to display on the top of category archive pages.

So for each category, I have one landing_page entry tagged with that category. What do I have to add to the category archive.php template to get it to show that category's (or custom taxonomy term's) landing_page content?

    array( 'posts_per_page' => 1,
    'post_type' => landing_page,
    'category' => [[???]] ));

     while (have_posts()) : the_post();
share|improve this question
up vote 1 down vote accepted

I'd suggest adding something like this to the top of the theme file or wherever you want this content to appear in the archive, category or whatever..

// Check if it's a category or taxonomy archive
if( is_category() || is_tax() ) {
    // Grab the queried data, slug, tax, etc..
    $queried = $wp_query->get_queried_object();
    // Check taxonomy and slug are set
    if( isset( $queried->taxonomy ) && isset( $queried->slug ) ) {
        // Look for a landing page post type with a slug that matches the current queried slug
        $landing_page = get_posts( 'name=' . $queried->slug . '&post_type=landing_page&posts_per_page=1&nopaging=1' );
        // If the result wasn't empty
        if( !empty( $landing_page ) ) {
            // Output the title and content using the same filters WP uses in the loop
            echo apply_filters( 'the_title', get_the_title( $landing_page->ID ) );
            echo apply_filters( 'the_content', get_the_content( $landing_page->ID ) );

This will should do what you want without interupting the main category query for the archive.

Hope that helps.

share|improve this answer
Looks good... but get_posts will return an array, so I think you might have to refer to $landing_page[0]->ID to get the title and content. – goldenapples Apr 7 '11 at 23:18
I might use new WP_Query() instead of get_posts(). I have yet to fully understand the differential efficiency/best practices surrounding WP_Query/get_posts/query_posts (even with explanatory diagrams like this: wordpress.stackexchange.com/questions/1753/…)—but my understanding is that the others involve WP_Query, so using WP_Query itself is more direct. – supertrue Jun 27 '11 at 16:46

You can get the current category with

and since you are using archive.php and not category.php check if its a category first so something like this:

if (is_category()){
    array( 'posts_per_page' => 1,
    'post_type' => 'landing_page',
    'category' =>  get_query_var('cat'));

     while (have_posts()) : the_post();

share|improve this answer
Missing quotes around your post type value.. ;) – t31os Mar 8 '11 at 14:18
thanks i edited my answer – Bainternet Mar 8 '11 at 14:20

Your Answer


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.