Advertisement
Guest User

custom-post-types

a guest
Jun 27th, 2011
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.85 KB | None | 0 0
  1. //Code from functions.php
  2.  
  3. add_action("init", "faqs_register");
  4.  
  5. function faqs_register() {
  6.  
  7.     $labels = array(
  8.         'name' => _x('FAQs', 'post type general name'),
  9.         'singular_name' => _x('FAQ Item', 'post type singular name'),
  10.         'add_new' => _x('Add New', 'FAQ item'),
  11.         'add_new_item' => __('Add New FAQ'),
  12.         'edit_item' => __('Edit FAQ'),
  13.         'new_item' => __('New FAQ'),
  14.         'view_item' => __('View FAQ'),
  15.         'search_items' => __('Search FAQ'),
  16.         'not_found' =>  __('Nothing found'),
  17.         'not_found_in_trash' => __('Nothing found in Trash'),
  18.         'parent_item_colon' => ''
  19.     );
  20.  
  21.     $args = array(
  22.         'labels' => $labels,
  23.         'public' => true,
  24.         'publicly_queryable' => true,
  25.         'show_ui' => true,
  26.         'query_var' => true,
  27.         'menu_icon' => get_stylesheet_directory_uri() . '/icons/faqs.png',
  28.         'rewrite' => array('slug' => 'faqs'),
  29.         'capability_type' => 'post',
  30.         'hierarchical' => false,
  31.         'menu_position' => 4,
  32.         'supports' => array('title','editor','thumbnail')
  33.       );
  34.  
  35.     register_post_type( 'faq' , $args );
  36.     flush_rewrite_rules();
  37. }
  38.  
  39. //And code from page template
  40.  
  41. <?php
  42. //http://codex.wordpress.org/Pages#A_Page_of_Posts_for_a_Custom_Post_Type
  43. /**
  44.  * Template Name: Page of Articles
  45. **/
  46. ?>
  47.  
  48. <?php get_header(); ?>
  49.  
  50.         <div id="container">
  51.             <div id="content">
  52. <?php
  53. $type = 'faq';
  54. $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  55. $args=array(
  56.   'post_type' => $type,
  57.   'post_status' => 'publish',
  58.   'paged' => $paged,
  59.   'posts_per_page' => 2,
  60.   'caller_get_posts'=> 1
  61. );
  62. //echo "<p>page: ".$paged."</p>";
  63. $temp = $wp_query;  // assign orginal query to temp variable for later use  
  64. $wp_query = null;
  65. $wp_query = new WP_Query($args);
  66. $wp_query->query($args);
  67. ?>
  68.  
  69. <?php get_template_part( 'loop', 'index' );?>
  70.  
  71.             </div><!-- #content -->
  72.         </div><!-- #container -->
  73. <?php get_sidebar(); ?>
  74. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement