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.

In WordPress there is defined a simple routing

/%postname%/

So when I access /projects/ it loads me Projects page which has specified custom template_projects.php template.

Is it possible to extend routing but only for this template ?

Let's say I want to extend routing to handle project id, so it should be:

/%postname%/%project-id%/

But other pages will work with base route.

share|improve this question
    
Have you tried endpoints? –  toscho Aug 9 '13 at 8:56
    
@toscho endpoints don't suit in this case... –  Eugene Manuilov Aug 9 '13 at 10:23
add comment

1 Answer

In your case you need to register custom post type for your projects. You can do it by using register_post_type function:

add_action( 'init', 'wpse8170_register_post_type' );
function wpse8170_register_post_type() {
    register_post_type( 'wpse8170-projects', array(
        'label'   => 'Projects',
        'public'  => true,
        'rewrite' => array( 'slug' => 'project' ),
    ) );
}

Don't forget to flush rewrite rules.

After you register your custom post type, your projects will have /project/%wpse8170-projects% (%wpse8170-project% will be replaced by project slug) permalink structure and you will be able to use single-wpse8170-projects.php template for your projects.

share|improve this answer
    
Explain me please, why there is wpse8170 keyword ? –  hsz Aug 9 '13 at 10:39
    
I have already did it, but I want to 'consume' projects in specified Page. So I have to fetch project in /projects/project-slug but projects post has to be available too. –  hsz Aug 9 '13 at 10:41
    
@hsz wpse8170 is unique prefix which prevents collision issues. You can pick up your own unique prefix and use it in your development. –  Eugene Manuilov Aug 9 '13 at 11:35
    
@hsz use archive-wpse8170-projects.php template to render archive page for project posts. In this template, fetch projects post/page and render it's content instead of rendering projects list. –  Eugene Manuilov Aug 9 '13 at 11:39
add comment

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.