Want more features on Pastebin? Sign Up, it's FREE!
Guest

Permalink Problems with custom post/taxonomy

By: a guest on Jul 8th, 2010  |  syntax: None  |  size: 2.75 KB  |  views: 145  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /***Custom Post Type : Portfolio***/
  2. add_action('init', 'portfolio');
  3. function portfolio()
  4. {
  5.   $labels = array(
  6.     'name' => _x('Portfolios', 'post type general name'),
  7.     'singular_name' => _x('Portfolio', 'post type singular name'),
  8.     'add_new' => _x('Add New', 'portfolio'),
  9.     'add_new_item' => __('Add New Portfolio'),
  10.     'edit_item' => __('Edit Portfolio'),
  11.     'new_item' => __('New Portfolio'),
  12.     'view_item' => __('View Portfolio'),
  13.     'search_items' => __('Search Portfolios'),
  14.     'not_found' =>  __('No portfolios found'),
  15.     'not_found_in_trash' => __('No portfolios found in Trash'),
  16.     'parent_item_colon' => ''
  17.   );
  18.   $args = array(
  19.     'labels' => $labels,
  20.     'public' => true,
  21.     'publicly_queryable' => true,
  22.     'show_ui' => true,
  23.     'query_var' => true,
  24.     'rewrite' => true,
  25.     'capability_type' => 'post',
  26.     'hierarchical' => false,
  27.     'menu_position' => 4,
  28.     'supports' => array('title','editor','thumbnail','custom-fields')
  29.   );
  30.   register_post_type('portfolio',$args);
  31. }
  32.  
  33.  
  34.  
  35.  
  36. //hook into the init action and call create_book_taxonomies when it fires
  37. add_action( 'init', 'create_portfolio_taxonomies', 0 );
  38.  
  39. //create two taxonomies, genres and writers for the post type "book"
  40. function create_portfolio_taxonomies()
  41. {
  42.   // Add new taxonomy, make it hierarchical (like categories)
  43.   $labels = array(
  44.     'name' => _x( 'Projects', 'taxonomy general name' ),
  45.     'singular_name' => _x( 'Project', 'taxonomy singular name' ),
  46.     'search_items' =>  __( 'Search Projects' ),
  47.     'all_items' => __( 'All Projects' ),
  48.     'parent_item' => __( 'Parent Project' ),
  49.     'parent_item_colon' => __( 'Parent Project:' ),
  50.     'edit_item' => __( 'Edit Project' ),
  51.     'update_item' => __( 'Update Project' ),
  52.     'add_new_item' => __( 'Add New Project' ),
  53.     'new_item_name' => __( 'New Project Name' ),
  54.   );    
  55.  
  56.   register_taxonomy('genre',array('portfolio'), array(
  57.     'hierarchical' => true,
  58.     'labels' => $labels,
  59.     'show_ui' => true,
  60.     'query_var' => true,
  61.     'rewrite' => array('slug' => 'portfolio', 'with_front' => FALSE)
  62.   ));
  63. }
  64.  
  65.  
  66.  
  67.  
  68. Then I'm using this code on my custom page template to show the posts.
  69.  
  70. <?php
  71. $args=array(
  72.   'genre' => 'web',
  73.   'post_type' => 'portfolio',
  74.   'post_status' => 'publish',
  75.   'posts_per_page' => -1,
  76.   'caller_get_posts'=> 1
  77. );
  78. $my_query = null;
  79. $my_query = new WP_Query($args);
  80. if( $my_query->have_posts() ) {
  81.   while ($my_query->have_posts()) : $my_query->the_post(); ?>
  82.     <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
  83. <p><?php the_content(); ?></p>
  84.     <?php
  85.   endwhile;
  86. }
  87. wp_reset_query();  // Restore global post data stomped by the_post().
  88. ?>
clone this paste RAW Paste Data