Advertisement
imranmodel32

Custom post type with box pagination

Dec 11th, 2013
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. /*gallery post type on function.php*/
  2.  
  3. add_action('init', 'gallery_init');
  4. function gallery_init()
  5. {
  6. $project_labels = array(
  7. 'name' => _x('Gallery', 'post type general name'),
  8. 'singular_name' => _x('Gallery', 'post type singular name'),
  9. 'all_items' => __('All Gallery'),
  10. 'add_new' => _x('Add new Gallery', 'project'),
  11. 'add_new_item' => __('Add new Gallery'),
  12. 'edit_item' => __('Edit Gallery'),
  13. 'new_item' => __('New Gallery'),
  14. 'view_item' => __('View Gallery'),
  15. 'search_items' => __('Search in Gallery'),
  16. 'not_found' => __('No Gallery found'),
  17. 'not_found_in_trash' => __('No Gallery found in trash'),
  18. 'parent_item_colon' => ''
  19. );
  20. $args = array(
  21. 'labels' => $project_labels,
  22. 'public' => true,
  23. 'publicly_queryable' => true,
  24. 'show_ui' => true,
  25. 'query_var' => true,
  26. 'rewrite' => true,
  27. 'capability_type' => 'post',
  28. 'hierarchical' => false,
  29. 'menu_position' => 5,
  30. 'supports' => array('title', 'editor','thumbnail'),
  31. 'has_archive' => 'gallery'
  32. );
  33. register_post_type('gallery',$args);
  34. }
  35.  
  36.  
  37.  
  38. function nyPaginate($end_size = 1, $mid_size = 5, $show_prev_next = true, $prev_text = '< Previous', $next_text = 'Next >', $pagi_type = 'list'){
  39. global $wp_query;
  40.  
  41. $big = 999999999; // need an unlikely integer
  42.  
  43. $args = array(
  44. 'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
  45. 'format' => '?page=%#%',
  46. 'total' => $wp_query->max_num_pages,
  47. 'current' => max( 1, get_query_var('paged') ),
  48. 'show_all' => false,
  49. 'end_size' => $end_size,
  50. 'mid_size' => $mid_size,
  51. 'prev_next' => $show_prev_next,
  52. 'prev_text' => $prev_text,
  53. 'next_text' => $next_text,
  54. 'type' => $pagi_type, // plain, list, array
  55. 'add_args' => false,
  56. 'add_fragment' => ''
  57. );
  58.  
  59. echo paginate_links( $args );
  60. }
  61.  
  62.  
  63.  
  64.  
  65. /* qurey on page*/
  66. <?php
  67. $temp = $wp_query;
  68. $wp_query = null;
  69. $wp_query = new WP_Query();
  70. $show_posts = 1; //How many post you want on per page
  71. $permalink = 'Post name'; // Default, Post name
  72. $post_type = 'gallery';
  73.  
  74. //Know the current URI
  75. $req_uri = $_SERVER['REQUEST_URI'];
  76.  
  77. //Permalink set to default
  78. if($permalink == 'Default') {
  79. $req_uri = explode('paged=', $req_uri);
  80.  
  81. if($_GET['paged']) {
  82. $uri = $req_uri[0] . 'paged=';
  83. } else {
  84. $uri = $req_uri[0] . '&paged=';
  85. }
  86. //Permalink is set to Post name
  87. } elseif ($permalink == 'Post name') {
  88. if (strpos($req_uri,'page/') !== false) {
  89. $req_uri = explode('page/',$req_uri);
  90. $req_uri = $req_uri[0] ;
  91. }
  92. $uri = $req_uri . 'page/';
  93.  
  94. }
  95.  
  96. //Query
  97. $wp_query->query('showposts='.$show_posts.'&post_type='. $post_type .'&paged='.$paged);
  98. //count posts in the custom post type
  99. $count_posts = wp_count_posts('projects');
  100.  
  101. while ($wp_query->have_posts()) : $wp_query->the_post();
  102. ?>
  103. <!--Do stuff-->
  104. <h1>
  105. <?php the_title(); ?>
  106. </h1>
  107. <?php the_content(); ?>
  108. <?php endwhile;?>
  109. <?php nyPaginate ( $mid_size = 8, $show_prev_next = true, $prev_text = '<', $next_text = '>', $pagi_type = 'list' );?>
  110.  
  111. <?php
  112. $wp_query = null;
  113. $wp_query = $temp; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement