Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*gallery post type on function.php*/
- add_action('init', 'gallery_init');
- function gallery_init()
- {
- $project_labels = array(
- 'name' => _x('Gallery', 'post type general name'),
- 'singular_name' => _x('Gallery', 'post type singular name'),
- 'all_items' => __('All Gallery'),
- 'add_new' => _x('Add new Gallery', 'project'),
- 'add_new_item' => __('Add new Gallery'),
- 'edit_item' => __('Edit Gallery'),
- 'new_item' => __('New Gallery'),
- 'view_item' => __('View Gallery'),
- 'search_items' => __('Search in Gallery'),
- 'not_found' => __('No Gallery found'),
- 'not_found_in_trash' => __('No Gallery found in trash'),
- 'parent_item_colon' => ''
- );
- $args = array(
- 'labels' => $project_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','thumbnail'),
- 'has_archive' => 'gallery'
- );
- register_post_type('gallery',$args);
- }
- function nyPaginate($end_size = 1, $mid_size = 5, $show_prev_next = true, $prev_text = '< Previous', $next_text = 'Next >', $pagi_type = 'list'){
- global $wp_query;
- $big = 999999999; // need an unlikely integer
- $args = array(
- 'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
- 'format' => '?page=%#%',
- 'total' => $wp_query->max_num_pages,
- 'current' => max( 1, get_query_var('paged') ),
- 'show_all' => false,
- 'end_size' => $end_size,
- 'mid_size' => $mid_size,
- 'prev_next' => $show_prev_next,
- 'prev_text' => $prev_text,
- 'next_text' => $next_text,
- 'type' => $pagi_type, // plain, list, array
- 'add_args' => false,
- 'add_fragment' => ''
- );
- echo paginate_links( $args );
- }
- /* qurey on page*/
- <?php
- $temp = $wp_query;
- $wp_query = null;
- $wp_query = new WP_Query();
- $show_posts = 1; //How many post you want on per page
- $permalink = 'Post name'; // Default, Post name
- $post_type = 'gallery';
- //Know the current URI
- $req_uri = $_SERVER['REQUEST_URI'];
- //Permalink set to default
- if($permalink == 'Default') {
- $req_uri = explode('paged=', $req_uri);
- if($_GET['paged']) {
- $uri = $req_uri[0] . 'paged=';
- } else {
- $uri = $req_uri[0] . '&paged=';
- }
- //Permalink is set to Post name
- } elseif ($permalink == 'Post name') {
- if (strpos($req_uri,'page/') !== false) {
- $req_uri = explode('page/',$req_uri);
- $req_uri = $req_uri[0] ;
- }
- $uri = $req_uri . 'page/';
- }
- //Query
- $wp_query->query('showposts='.$show_posts.'&post_type='. $post_type .'&paged='.$paged);
- //count posts in the custom post type
- $count_posts = wp_count_posts('projects');
- while ($wp_query->have_posts()) : $wp_query->the_post();
- ?>
- <!--Do stuff-->
- <h1>
- <?php the_title(); ?>
- </h1>
- <?php the_content(); ?>
- <?php endwhile;?>
- <?php nyPaginate ( $mid_size = 8, $show_prev_next = true, $prev_text = '<', $next_text = '>', $pagi_type = 'list' );?>
- <?php
- $wp_query = null;
- $wp_query = $temp; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement