douyi1966 2015-03-01 23:03
浏览 26

自定义帖子类型分页问题

Having trouble implementing the pagination for custom post type ('vehicle') in Genesis child theme, I'm using Genesis : 2.0.0 in wordpress 4.1.1

I've tried placing the following code in function.php add_filter( 'genesis_prev_link_text', 'gt_review_prev_link_text' );

function gt_review_prev_link_text() {
        $prevlink = '« Previous Reviews';
        return $prevlink;
}
add_filter( 'genesis_next_link_text', 'gt_review_next_link_text' );
function gt_review_next_link_text() {
        $nextlink = 'Next Reviews »';
        return $nextlink;
} 

i've tried the following too;

<?php genesis_posts_nav();?>

The code below works, but only as 'newer' and 'older' hyperlinks, i'm trying to achieve a numeric pagination.

<?php previous_posts_link( '« Newer' ); ?>
<?php next_posts_link( 'Older »', $vehicle->max_num_pages ); ?>

Here is my custom post type archive template.

<?php
/*
Template Name: Archive Vehicle(CAR)
*/
//* Force full width content
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' );
//* Remove Post Info
remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );

//* Remove Post Meta
remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_open', 5 );
remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_close', 15 );
remove_action( 'genesis_entry_footer', 'genesis_post_meta' );
 /** Code for custom loop */

remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'am_custom_loop' );
function am_custom_loop(){
$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 = array('post_type' => 'vehicle', 'posts_per_page' => '3', 'paged'=> $paged, );
   $vehicle = new WP_query($args);
$wp_query = $vehicle;
                if ($vehicle -> have_posts() ){
?>
<div class="first arc">
<h2> View our latest used car collection from KH cars Birmingham</h2>
<p>Need a car?  Look no further, browse through our vast selection of used cars on site based in Birmingham.  </p>
</div>
<?php
                while ($vehicle -> have_posts() ){
                $vehicle -> the_post();

?>

<div class="first archivecar">
    <div class="one-fourth">  
<?php 
$images = get_field('image');
    if( $images ): 
        $image = $images[0];
?>                
            <a href="<?php the_permalink($id); ?>">
                <img src="<?php echo $images[0]['sizes']['large']; ?>" alt="<?php echo $image['alt']; ?>" />
            </a> 
<?php endif; ?>
         </div>
       <div class="two-fourths">
<br>
            <h3><a  style="text-decoration:none;" href="<?php the_permalink($id) ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
<ul class="carinfo">
    <li><p> Year: <?php $terms = get_the_terms( $post->ID , 'year', 'year' );
 // Loop over each item since it's an array
 if ( $terms != null ){
 foreach( $terms as $term ) {
 // Print the name method from $term which is an OBJECT
 print $term->name ;
 // Get rid of the other data stored in the object, since it's not needed
 unset($term);
} } ?></p></li>
    <li><p> Trans: <?php $terms = get_the_terms( $post->ID , 'trans', 'trans' );
 // Loop over each item since it's an array
 if ( $terms != null ){
 foreach( $terms as $term ) {
 // Print the name method from $term which is an OBJECT
 print $term->name ;
 // Get rid of the other data stored in the object, since it's not needed
 unset($term);
} } ?></p></li>
   <li><p> Fuel: 
  <?php   // Get terms for post
 $terms = get_the_terms( $post->ID , 'fuel', 'fuel' );
 // Loop over each item since it's an array
 if ( $terms != null ){
 foreach( $terms as $term ) {
 // Print the name method from $term which is an OBJECT
 print $term->name ;
 // Get rid of the other data stored in the object, since it's not needed
 unset($term);
} } ?></li>
 <?php if( get_field('Mileage') ): ?>
    <li><p> Mileage: <?php the_field('Mileage');?></p></li>
 <?php endif; ?>
    <li><p>Color: <?php $terms = get_the_terms( $post->ID , 'colours', 'colours' );
 // Loop over each item since it's an array
 if ( $terms != null ){
 foreach( $terms as $term ) {
 // Print the name method from $term which is an OBJECT
 print $term->name ;
 // Get rid of the other data stored in the object, since it's not needed
 unset($term);
} } ?></p></li>
 <?php if( get_field('owners') ): ?>
    <li><p>Owners: <?php $terms = get_the_terms( $post->ID , 'owners', 'owners' );
 // Loop over each item since it's an array
 if ( $terms != null ){
 foreach( $terms as $term ) {
 // Print the name method from $term which is an OBJECT
 print $term->name ;
 // Get rid of the other data stored in the object, since it's not needed
 unset($term);
} }?></p></li>
 <?php endif; ?>
</ul>
</div>
<div class="one-fourth">

        <?php if ( get_field('price')):?>
    <p class="price"><?php the_field('price');?></p>
    <?php endif; ?>
<a class="btn" style="text-align:center" href="<?php the_permalink() ?>">view Details</a>
</div>
</div>
<?php
}
?>
<?php genesis_posts_nav();?>
<?php wp_reset_query();?>
<?php
}
}
genesis();

Any Help is much appreciated. Thanks in advance

  • 写回答

1条回答 默认 最新

  • doujiang9887 2015-03-02 00:57
    关注

    First i Removed $wp_query = $vehicle; and then used the code below from wordpress codex and voila it works.

    <?php
    $big = 999999999; // need an unlikely integer
    
    echo paginate_links( array(
        'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
        'format' => '?paged=%#%',
        'current' => max( 1, get_query_var('paged') ),
        'total' => $vehicle->max_num_pages
    ) );
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥100 iOS开发关于快捷指令截屏后如何将截屏(或从截屏中提取出的文本)回传给本应用并打开指定页面
  • ¥15 unity连接Sqlserver
  • ¥15 图中这种约束条件lingo该怎么表示出来
  • ¥15 VSCode里的Prettier如何实现等式赋值后的对齐效果?
  • ¥15 流式socket文件传输答疑
  • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式
  • ¥50 关于多次提交POST数据后,无法获取到POST数据参数的问题
  • ¥15 win10,这种情况怎么办
  • ¥15 如何在配置使用Prettier的VSCode中通过Better Align插件来对齐等式?(相关搜索:格式化)
  • ¥100 在连接内网VPN时,如何同时保持互联网连接