• Resolved sschmitt

    (@sschmitt)


    I created a custom post-type called “Characters” . There are also custom taxonomies to go with it. These would be different series that the characters are from. i.e. Characters > Nancy Drew.

    I need to create a custom archive page for the characters of Nancy Drew. I have searched High and Low to figure this out. I got half way and I am posting the link below. I was able to make an archive page for “Characters” but I can’t figure out how display posts for Nancy Drew.

    I have read posts that have to do with setting up Custom Post-Types but get confused on the archive part. Some of the resolutions are in functions.php and some are in the actual code of the archive-characters.php file. I can’t get the combo correct.

    I will attached the code from my functions.php file to see if I have all info there. I will also include the code from archive-characters.php… and of course link.

    Any help would really be appreciated as I have been trying to figure this out for a couple days now.

    Thanks a bunch!

    Sandra 🙂

    Link:

    http://test.papercutz.com/characters/

    Functions code:

    <?php
    
    // Add Custom Post Types
    add_action('init', 'papercutz_characters_init');
    function papercutz_characters_init()
    {
    	$character_labels = array(
    		'name' => _x('Characters', 'post type general name'),
    		'singular_name' => _x('Character', 'post type singular name'),
    		'all_items' => __('All Characters'),
    		'add_new' => _x('Add new characters', 'characters'),
    		'add_new_item' => __('Add new characters'),
    		'edit_item' => __('Edit characters'),
    		'new_item' => __('New characters'),
    		'view_item' => __('View characters'),
    		'search_items' => __('Search in characters'),
    		'not_found' =>  __('No characters found'),
    		'not_found_in_trash' => __('No characters found in trash'),
    		'parent_item_colon' => ''
    	);
    	$args = array(
    		'labels' => $character_labels,
    		'public' => true,
    		'publicly_queryable' => true,
    		'show_ui' => true,
    		'query_var' => true,
    		'rewrite' => true,
    		'capability_type' => 'post',
    		'hierarchical' => false,
    		'menu_position' => 5,
    		'supports' => array('title','editor','author','thumbnail','excerpt','comments','custom-fields'),
    		'has_archive' => 'characters'
    	);
    	register_post_type('characters',$args);
    }
    add_action('init', 'papercutz_authors_init');
    function papercutz_authors_init()
    {
    	$author_labels = array(
    		'name' => _x('Authors & Artists', 'post type general name'),
    		'singular_name' => _x('Author & Artist', 'post type singular name'),
    		'all_items' => __('All Authors & Artists'),
    		'add_new' => _x('Add new Authors & Artists', 'authors'),
    		'add_new_item' => __('Add new authors & artists'),
    		'edit_item' => __('Edit authors & artists'),
    		'new_item' => __('New authors & artists'),
    		'view_item' => __('View authors & artists'),
    		'search_items' => __('Search in authors & artists'),
    		'not_found' =>  __('No authors & artists found'),
    		'not_found_in_trash' => __('No authors & artists found in trash'),
    		'parent_item_colon' => ''
    	);
    	$args = array(
    		'labels' => $author_labels,
    		'public' => true,
    		'publicly_queryable' => true,
    		'show_ui' => true,
    		'query_var' => true,
    		'rewrite' => true,
    		'capability_type' => 'post',
    		'hierarchical' => false,
    		'menu_position' => 5,
    		'supports' => array('title','editor','author','thumbnail','excerpt','comments','custom-fields'),
    		'has_archive' => 'authors'
    	);
    	register_post_type('authors',$args);
    }
    add_action('init', 'papercutz_buzz_init');
    function papercutz_buzz_init()
    {
    	$buzz_labels = array(
    		'name' => _x('Buzz', 'post type general name'),
    		'singular_name' => _x('Buzz', 'post type singular name'),
    		'all_items' => __('All Buzz'),
    		'add_new' => _x('Add new Buzz', 'buzz'),
    		'add_new_item' => __('Add new Buzz'),
    		'edit_item' => __('Edit Buzz'),
    		'new_item' => __('New Buzz'),
    		'view_item' => __('View Buzz'),
    		'search_items' => __('Search in Buzz'),
    		'not_found' =>  __('No Buzz found'),
    		'not_found_in_trash' => __('No Buzz found in trash'),
    		'parent_item_colon' => ''
    	);
    	$args = array(
    		'labels' => $buzz_labels,
    		'public' => true,
    		'publicly_queryable' => true,
    		'show_ui' => true,
    		'query_var' => true,
    		'rewrite' => true,
    		'capability_type' => 'post',
    		'hierarchical' => false,
    		'menu_position' => 5,
    		'supports' => array('title','editor','author','thumbnail','excerpt','comments','custom-fields'),
    		'has_archive' => 'buzz'
    	);
    	register_post_type('buzz',$args);
    }
    
    // Add custom taxonomies
    add_action( 'init', 'papercutz_create_taxonomies', 0 );
    
    function papercutz_create_taxonomies()
    {
    	// Comic Series
    	$series_labels = array(
    		'name' => _x( 'Comic Series', 'taxonomy general name' ),
    		'singular_name' => _x( 'Comic Series', 'taxonomy singular name' ),
    		'search_items' =>  __( 'Search in comic series' ),
    		'all_items' => __( 'All comic series' ),
    		'most_used_items' => null,
    		'parent_item' => null,
    		'parent_item_colon' => null,
    		'edit_item' => __( 'Edit comic series' ),
    		'update_item' => __( 'Update comic series' ),
    		'add_new_item' => __( 'Add new comic series' ),
    		'new_item_name' => __( 'New comic series' ),
    		'menu_name' => __( 'Comic Series' ),
    	);
    	register_taxonomy('comic-series', array('characters','authors','buzz'), array(
    		'hierarchical' => true,
    		'labels' => $series_labels,
    		'show_ui' => true,
    		'query_var' => true,
    		'rewrite' => array('slug' => 'comic-series' )
    	));
    }
    
    ?>

    archive-characters.php:

    <?php get_header(); ?>
    
      <div id="main-content-wrap2">
    
      <div id="main-content">
    
      <h3> This file is archive-characters.php it is not attached to a page template. it is called up by url. other than that cannot find out how to link to it</h3>
    
    		<?php if (have_posts()) : ?>
    
     			<?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
    
    			<?php /* If this is a category archive */ if (is_category()) { ?>
    				<h2>Archive for the ‘<?php single_cat_title(); ?>’ Category</h2>
    
    			<?php /* If this is a tag archive */ } elseif( is_tag() ) { ?>
    				<h2>Posts Tagged ‘<?php single_tag_title(); ?>’</h2>
    
    			<?php /* If this is a daily archive */ } elseif (is_day()) { ?>
    				<h2>Archive for <?php the_time('F jS, Y'); ?></h2>
    
    			<?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
    				<h2>Archive for <?php the_time('F, Y'); ?></h2>
    
    			<?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
    				<h2>Archive for <?php the_time('Y'); ?></h2>
    
    			<?php /* If this is an author archive */ } elseif (is_author()) { ?>
    				<h2>Author Archive</h2>
    
    			<?php /* If this is a paged archive */ } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { ?>
    				<h2>Blog Archives</h2>
    
    			<?php } ?>
    
    			<?php include (TEMPLATEPATH . '/inc/nav.php' ); ?>
    
    			<?php while (have_posts()) : the_post(); ?>
    
    				<div <?php post_class() ?>>
    
    					<h2 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
    
    					<?php include (TEMPLATEPATH . '/inc/meta.php' ); ?>
    
    					<div class="entry">
    						<?php the_content(); ?>
    					</div>
    
    				</div>
    
    			<?php endwhile; ?>
    
    			<?php include (TEMPLATEPATH . '/inc/nav.php' ); ?>
    
    	<?php else : ?>
    
    		<h2>Nothing found</h2>
    
    	<?php endif; ?>
    
            </div><!-- END main-content -->
    
    <?php get_sidebar(); ?>
    
    </div><!-- END main-content-wrap -->
    
    <?php get_footer(); ?>
Viewing 1 replies (of 1 total)
  • Thread Starter sschmitt

    (@sschmitt)

    I ended up using a plugin that has been really helpful. It’s called Custom Taxonomies Menu Widget which basically has custom taxonomies use the archive.php file. Maybe Wp uses archive.php file automatically, I am no expert, but I got it to work and I am trilled! From there I made custom archive.php files co I could customize different categories. Hope this helps 🙂

Viewing 1 replies (of 1 total)
  • The topic ‘Create Custom Post-type Category Archive Page’ is closed to new replies.