WordPress.org

Ready to get started?Download WordPress

Forums

Custom Post Type and Category.php (2 posts)

  1. roothost
    Member
    Posted 2 years ago #

    Ok, been at this now since 9pm last night!! I created a custom post type called 'scrapbooks'. Added the default WP category to this post type using:

    <?php
    add_action( 'init', 'wpse6098_init', 100 ); // 100 so the post type has been registered
    function wpse6098_init()
    {
        register_taxonomy_for_object_type( 'category', 'scrapbooks' );
    }
    ?>

    Anyway, that works great, displays cats, etc etc. The problem comes when Iclick on a cat to view all posts in that cat, it just displays EVERY post in the custom post type. Now I have tried everything I can think of to fix this, but no joy.

    I even tried custom category templates and that didnt work, so am back to using the standard category.php (it isn't called anywhere else) and that is

    <?php get_header(); ?>
    
    <div class="page-overlay">
    <div id="page-wrapper"><div class="fake-close"><a title="Pop-up Books from Sussex Paper Engineer" href="http://www.corinaandco.com"><img src="http://www.corinaandco.com/wp-content/themes/candco/img/close.png" alt="Close" /></a></div>
    <div id="diary-page-wrapper">
    <div id="diary-top"></div><!-- /#diary-top -->
    <div id="diary-middle">
    <div id="diary-left">
    <?php query_posts('post_type=scrapbooks'); while (have_posts()) : the_post(); ?>
    <div class="diary-date-info"><span class="times-new-roman"><?php the_time('M n') ?> | </span><?php the_category(' '); ?></div><!-- /.diary-date-info -->
    <div class="diary-post-content">
    <h1><?php the_title(); ?></h1>
    <?php the_content(); /* Print the content we just got */ ?>
    </div><!-- /.diary-post-content -->
    <?php endwhile; ?>
    </div><!-- /#diary-left -->
    
    <div id="diary-right">
    <div class="diary-right-header"><span class="times-new-roman">Notes |</span></div><!-- /.diary-right-header -->
    
    <div id="diary-right-float">
    <div class="diary-right-float-left"><img class="diary-float-left-img" src="http://www.corinaandco.com/wp-content/themes/candco/img/corina-fletcher-books.jpg" alt="The Bookshelf" title="The Bookshelf"><span class="diary-float-left-desc">THE BOOKSHELF</span><img class="diary-float-left-img" src="http://www.corinaandco.com/wp-content/themes/candco/img/basil-the-studio-dog.jpg" alt="Basil, the studio Dog" title="Basil, the studio Dog"><span class="diary-float-left-desc">THE STUDIO DOG (Basil)</span><img class="diary-float-left-img" src="http://www.corinaandco.com/wp-content/themes/candco/img/corina-fletcher.jpg" alt="Corina Fletcher" title="Corina Fletcher"><span class="diary-float-left-desc">CORINA</span></div><!-- /.diary-right-float-left -->
    
    <div class="diary-right-float-right"><div class="diary-right-categories"><ul><li>Category Index:</li><?php wp_list_cats('exclude=1'); ?></ul></div><!-- /.diary-right-categories --><img class="diary-float-left-img" src="http://www.corinaandco.com/wp-content/themes/candco/img/paper-engineering-tools.jpg" alt="Corina's Paper Engineering tools" title="Corina's Paper Engineering tools"><span class="diary-float-left-desc">THE TOOLS</span><img class="diary-float-left-img" src="http://www.corinaandco.com/wp-content/themes/candco/img/lydia-crook.jpg" alt="The Elf, Lydia" title="The Elf, Lydia"><span class="diary-float-left-desc">THE ELF (Lydia)</span></div><!-- /.diary-right-float-right -->
    
    </div><!-- /#diary-right-float -->
    </div><!-- /#diary-right -->
    
    </div><!-- /#diary-middle -->
    <div id="diary-bottom"></div><!-- /#diary-bottom -->
    </div><!-- /#diary-page-wrapper -->
    </div><!-- /#page-wrapper -->
    </div><!-- /.page-overlay -->
    <?php get_footer(); ?>

    Really getting tired of this now, seems like the last hurdle lol.

  2. keesiemeijer
    moderator
    Posted 2 years ago #

    Is this the category.php you have now?
    this part query_posts('post_type=scrapbooks'); tells the loop to only show "scrapbooks" Post type Posts.
    Maybe you need:

    $current_cat = get_query_var('cat');
    query_posts('post_type=scrapbooks&cat='.$current_cat);

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.