0

I have made a custom post type called "Case Studies".

There is a case studies page which displays the title of every custom post and a small exceprt. However when you click on the title to view the single post, on the navigation the current tab changes from "Case studies" to "News". Where news is the default post page and case studies is a templated page.

Is there a way to make the custom post type a child of the Case Studies page? Or atleast set a template file that I can use for the custom post type. When you view a single case study post I need the navigation to show that you are still on the Case Studies page and not on News.

Thanks

3
  • how are the tabs activated at the moment? Using CSS? have you used firebug to see if you can tweak the rule to make it work for you?
    – Mild Fuzz
    Commented Sep 21, 2010 at 9:34
  • it uses wordpress's .current-page class.I cant use jquery to remove class and add the class to the right menu item because I need full no-javascript compatability. ):
    – adamtomat
    Commented Sep 21, 2010 at 10:32
  • 1
    Can you add the code from the menu for case studies and the single custom post type?
    – Chris_O
    Commented Sep 22, 2010 at 2:50

2 Answers 2

1
// Template redirect for custom templates
add_action( 'template_redirect', 'template_redirect' );

public function template_redirect() {
    global $wp_query;
    if ( $wp_query->query_vars['post_type'] == 'case_studies' ) {
        get_template_part( 'single-casestudies' ); // a custom page-slug.php template
        die();
    }
}

This is the same thing that @Dalton mentioned, you would want to create a custom page template named page-casestudies.php or whatever you want to name it, then make a page in WP admin that has a slug of 'casestudies' to match the page-{slug}.php or page-{id}.php where the page id matches. And you can use the page.php code, with a line or two before the if(have_posts() while(have_posts() Loop. Sort of like this:

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts( array( 'post_type' => 'case_studies', 'paged' => $paged ));

if (have_posts()) : while (have_posts()) : the_post();

Sorry if I misunderstood the problem, but I think this would fix it.

0

I believe you want to use the rewrite parameter to change the permalink to your custom post type. As far as creating a custom post template, the format is single-CUSTOMPOSTTYPE.php

Here's the reference I found for this: http://kovshenin.com/archives/extending-custom-post-types-in-wordpress-3-0/

For example, on my site I have a normal page called "Animation" which is a landing page for my custom post type (animations). My rewrite slug is 'animation' and my template is single-animation.php. The permalink structure looks like mysite.com/animation/name-of-animation

Your Answer

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

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