Customizing page type for Genesis child theme

Is it possible to implement pagination for custom post type in Genesis child theme, I am using Genesis: 2.0.2 and Wordpress version: 4.0.

I tried the following code in my template but it doesn't work for me.

<?php echo genesis_posts_nav(); ?>

      

And my normal pagination category also doesn't work for me in my genesis child theme.

<?php echo genesis_posts_nav(); ?>

      

My custom templated code is here:

<?php 

remove_action( 'genesis_loop', 'genesis_do_loop' );

add_action( 'genesis_loop', 'sk_do_loop' );

function sk_do_loop(){

$args_spotlight_latest = array('posts_per_page' => 5,'post_type' => 'spotlight', 'post_status'=>'publish','meta_key' => 'featured_slider','meta_value' => 'true');
$spotlight_posts_latest = new WP_Query($args_spotlight_latest);

/** Content Area **/

if($spotlight_posts_latest->have_posts()){

    while($spotlight_posts_latest->have_posts()){
    $spotlight_posts_latest->the_post();                        
    $feat_image = wp_get_attachment_url(get_post_thumbnail_id());   

    ..............
    ..............
    ..............
   }

}

genesis_posts_nav();

}

?>

      

Can anyone help me with this.

Thanks in advance.

+3


source to share


2 answers


use this code, it will definitely work, gives out a static page



remove_action( 'genesis_loop', 'genesis_do_loop' );

add_action( 'genesis_loop', 'sk_do_loop' );

function sk_do_loop(){
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args_spotlight_latest = array('posts_per_page' => 5,'post_type' => 'spotlight', 'paged' => $paged);
$spotlight_posts_latest = new WP_Query($args_spotlight_latest);

/** Content Area **/

if($spotlight_posts_latest->have_posts()){

    while($spotlight_posts_latest->have_posts()){
    $spotlight_posts_latest->the_post(); 


    echo "<h1>".the_title()."</h1>";
    the_content();

   }
   previous_posts_link( '« Newer' ); 
 next_posts_link( 'Older »', $spotlight_posts_latest->max_num_pages ); 

}


}

      

+2


source


Here's the final code:

<?php

remove_action( 'genesis_loop', 'genesis_do_loop' );

add_action( 'genesis_loop', 'sk_do_loop' );

function sk_do_loop(){

global $wp_query;
$temp_query = $wp_query;

// Fix for the WordPress 3.0 "paged" bug.
$paged = 1;
if ( get_query_var( 'paged' ) ) { $paged = get_query_var( 'paged' ); }
if ( get_query_var( 'page' ) ) { $paged = get_query_var( 'page' ); }
$paged = intval( $paged );

$args_spotlight_latest = array('posts_per_page' => 5,'post_type' => 'spotlight', 'post_status'=>'publish','meta_key' => 'featured_slider','meta_value' => 'true', 'paged' => $paged);
$spotlight_posts_latest = new WP_Query($args_spotlight_latest);
$wp_query = $spotlight_posts_latest;
/** Content Area **/

if($spotlight_posts_latest->have_posts()){

    while($spotlight_posts_latest->have_posts()){
    $spotlight_posts_latest->the_post();                        
    $feat_image = wp_get_attachment_url(get_post_thumbnail_id());   

    ..............
    ..............
    ..............
   }

}

genesis_posts_nav();

wp_reset_query();

}

      



? >

It works great :)

+1


source







All Articles