Genesis子主题的自定义投递类型分页

时间:2014-09-06 作者:John Peter

是否有可能在中实现自定义帖子类型的分页Genesis 儿童主题,我正在使用Genesis : 2.0.2和Wordpress 版本为:4.0。

我在模板中尝试了以下代码,但它对我无效。

<?php echo genesis_posts_nav(); ?>
在我的创世记儿童主题中,我的常规类别分页也不适用。

<?php echo genesis_posts_nav(); ?>

My Custom Template Code 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();

}

?>
有人能帮我吗。

提前谢谢。

1 个回复
最合适的回答,由SO网友:Chinmoy Kumar Paul 整理而成

EDIT

Try this code:

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();

}
结束

相关推荐

Custom template pagination

我有一个自定义的帖子类型“新闻”。我创建了id为55的“News”页面和一个自定义模板文件。我想实现分页。问题是,当我访问设置了页码的新闻时,会出现错误“404未找到”。URL类似于“/新闻/页面/2/”。我使用paginate_links 函数以显示分页。如何显示正确的页面?

Genesis子主题的自定义投递类型分页 - 小码农CODE - 行之有效找到问题解决它

Genesis子主题的自定义投递类型分页

时间:2014-09-06 作者:John Peter

是否有可能在中实现自定义帖子类型的分页Genesis 儿童主题,我正在使用Genesis : 2.0.2和Wordpress 版本为:4.0。

我在模板中尝试了以下代码,但它对我无效。

<?php echo genesis_posts_nav(); ?>
在我的创世记儿童主题中,我的常规类别分页也不适用。

<?php echo genesis_posts_nav(); ?>

My Custom Template Code 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();

}

?>
有人能帮我吗。

提前谢谢。

1 个回复
最合适的回答,由SO网友:Chinmoy Kumar Paul 整理而成

EDIT

Try this code:

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();

}

相关推荐

Count posts for pagination

我正在为一个网站分页<;上一页(页码)下一页>很简单,已经完成。但是现在我需要添加一个选择器来直接转到页面(例如:转到第7页),要这样做,我需要知道有多少页面,为此我需要计算在查询中找到了多少帖子。问题是这个网站有太多的帖子(>13.000),查询所有帖子都会减慢页面加载速度,这就像。。。10秒后页面才能加载。显然,这是不可接受的。分页解决了这个问题,因为一次只加载50或100篇文章,但我无法将它们全部计算在内。我可以在不加载的情况下统计某个查询中的帖子吗?或者我可以通过其他方式获得页数吗