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.

I know there is alot of discussion about the CPT and permlinks together with the 404. I did not found a solution though I am close. It would be great if someone could assist me to get it working.

Ok what I did is:

    function post_type_services() 
{    
    register_post_type( 'services',
                array( 
                'label' => __('Services'), 
                'singular_name' => __( 'Service' ),
                'capability_type' => 'post',
                'rewrite' => array('slug' => 'service','with_front' => FALSE),
                'public'  => true, 
                'show_ui' => true ) );     

    flush_rewrite_rules( false );
    }
add_action('init', 'post_type_services');

I added a CPT for services. I added a slug and I also added flush_rewrite_rules(false) as suggested in many blog posts.

I turned on Permlinks with the settings /%year%/%monthnum%/%postname% I added a file single-services.php which contains following content

   <?php 
    get_header(); 
?>
<div class="content">
    <div class="content_resize">
        <div class="mainbar">
    <?php query_posts('post_type=services'); ?>
    <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
    <div class="article">
                <h2><?php the_title(); ?></h2>
                <?php the_content(); ?>
                <?php wp_link_pages( array( 'before' => '' . __( 'Pages:', 'twentyten' ), 'after' => '' ) ); ?>
                <?php edit_post_link( __( 'Edit', 'twentyten' ), '', '' ); ?>
    </div>
        <?php endwhile; ?>
        </div>
        <div class="sidebar">
            <div class="gadget">
                <h2>Auswahl</h2>
                <div class="clr"></div>
                    <?php wp_nav_menu( array( 'sort_column' => 'menu_order', 'menu_class' => 'sb_menu', 'theme_location' => 'leftmain' ) ); ?>
            </div>
            <?php get_sidebar(); ?> 
        </div>
    </div>
    <div class="clr"></div>
</div>
<div class="fbg">
    <div class="fbg_resize">
            <div class="footer">
                <?php get_footer(); ?>
            </div>
    </div>
</div>

So far so good. What I want is. if I navigate to http://www.mydomain.com/service I would like to see my list of services and when I click on a single service I want to display the single service.

What I do get right now is when I navigate to http://www.mydomain.com/service. I get a 404 but when I visit http://www.mydomain.com/service/my-first-service I see the list of services...

What did I do wrong? How can I get a list of services when I visit http://www.mydomain.com/service ?

P.S.: I use the starkers base template to generate my own...

share|improve this question

1 Answer 1

up vote 1 down vote accepted

You need to add the following to your register_post_type() array:

'has_archive' => 'service'

share|improve this answer
    
you rock! Thanks!... –  server info Mar 10 '11 at 16:09
    
Glad it was a simple fix! :) –  tnorthcutt Mar 10 '11 at 16:42

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.