0

在Genesis子主题中实现自定义帖子类型('vehicle')的分页时遇到问题,我在wordpress 4.1.1中使用Genesis:2.0.0

我尝试将以下代码放在 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;
} 

我也尝试过以下方法;

<?php genesis_posts_nav();?>

下面的代码有效,但仅作为“较新”和“较旧”超链接,我试图实现数字分页。

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

这是我的自定义帖子类型存档模板。

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

任何帮助深表感谢。提前致谢

4

1 回答 1

0

首先我删除了 $wp_query = $vehicle; 然后使用wordpress codex中的以下代码,瞧,它可以工作了。

<?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
) );
?>
于 2015-03-02T00:57:41.057 回答