我正在尝试在[快捷方式]中添加分页。这是我的代码:
<?php }
//LatestCar Function
function carforyou_LatestCar($atts){
ob_start();?>
<div class="row">
<?php
extract( shortcode_atts(array('show' =>''), $atts ));
extract( shortcode_atts(array('brand' =>''), $atts ));
$loop = new WP_Query( array(
'post_type' => 'auto',
'auto-brand' => $brand,
'posts_per_page'=>$show,
'offset' => 0
));// $count = $loop->found_posts; echo $count;
while ($loop->have_posts()) : $loop->the_post();
global $post; ?>
<div class="col-list-3">
<div class="featured-car-list">
<div class="featured-car-img">
<a alt="<?php echo get_the_title(); ?>" title="<?php echo get_the_title(); ?>" href="<?php the_permalink();?>">
<?php if(has_post_thumbnail()):
the_post_thumbnail('carforyou_small', array('class' => 'img-responsive'));
else:
echo "<div class='is-empty-img-box'></div>";
endif;
?>
</a>
<?php carforyou_AutoType(); ?>
<div class="compare_item">
<div class="checkbox">
<button id="compare_auto_btn" onclick="<?php echo esc_js('javascript:productCompare('.$post->ID.')'); ?>"><?php esc_html_e('Compare','carforyou'); ?></button>
</div>
</div>
</div>
<div class="featured-car-content">
<h6><a title="<?php echo get_the_title(); ?>" href="<?php the_permalink(); ?>"><?php $title = get_the_title(); echo mb_strimwidth($title, 0, 30, '...'); ?></a></h6>
<div class="price_info">
<?php if(!empty($post->DREAM_auto_price)): ?>
<p class="featured-price"><?php carforyou_curcy_prefix(); ?><?php echo number_format_i18n(esc_html($post->DREAM_auto_price)); ?></p>
<?php endif; ?>
<div class="car-location">
<?php $term_list = wp_get_post_terms($post->ID, 'auto-location', array("fields" => "all"));
foreach($term_list as $term_single)
$location = $term_single->name;
?>
<?php if(!empty($location)): ?>
<span><i class="fa fa-map-marker" aria-hidden="true"></i> <?php echo esc_html($location); ?> </span>
<?php endif; ?>
</div>
</div>
<ul>
<?php carforyou_featuredList(); ?>
</ul>
</div>
</div>
</div>
<?php endwhile; wp_reset_query(); ?>
</div>
<?php }
以上使用[latestcars show =“ 10” brand =“ ford”]的代码可显示10辆福特制造的汽车。我想添加分页,所以我添加了以下修改:
<?php }
//LatestCar Function
function carforyou_LatestCar($atts){
ob_start();?>
<div class="row">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
extract( shortcode_atts(array('show' =>''), $atts ));
extract( shortcode_atts(array('brand' =>''), $atts ));
$loop = new WP_Query( array(
'post_type' => 'auto',
'auto-brand' => $brand,
'paged' =>$paged,
'posts_per_page'=>$show,
'offset' => 0
));
// $count = $loop->found_posts; echo $count;
while ($loop->have_posts()) : $loop->the_post();
global $paged, $post;
?>
<div class="col-list-3">
<div class="featured-car-list">
<div class="featured-car-img">
<a alt="<?php echo get_the_title(); ?>" title="<?php echo get_the_title(); ?>" href="<?php the_permalink();?>">
<?php if(has_post_thumbnail()):
the_post_thumbnail('carforyou_small', array('class' => 'img-responsive'));
else:
echo "<div class='is-empty-img-box'></div>";
endif;
?>
</a>
<?php carforyou_AutoType(); ?>
<div class="compare_item">
<div class="checkbox">
<button id="compare_auto_btn" onclick="<?php echo esc_js('javascript:productCompare('.$post->ID.')'); ?>"><?php esc_html_e('Compare','carforyou'); ?></button>
</div>
</div>
</div>
<div class="featured-car-content">
<h6><a title="<?php echo get_the_title(); ?>" href="<?php the_permalink(); ?>"><?php $title = get_the_title(); echo mb_strimwidth($title, 0, 30, '...'); ?></a></h6>
<div class="price_info">
<?php if(!empty($post->DREAM_auto_price)): ?>
<p class="featured-price"><?php carforyou_curcy_prefix(); ?><?php echo number_format_i18n(esc_html($post->DREAM_auto_price)); ?></p>
<?php endif; ?>
<div class="car-location">
<?php $term_list = wp_get_post_terms($post->ID, 'auto-location', array("fields" => "all"));
foreach($term_list as $term_single)
$location = $term_single->name;
?>
<?php if(!empty($location)): ?>
<span><i class="fa fa-map-marker" aria-hidden="true"></i> <?php echo esc_html($location); ?> </span>
<?php endif; ?>
</div>
</div>
<ul>
<?php carforyou_featuredList(); ?>
</ul>
</div>
</div>
</div>
<?php endwhile;
carforyou_pagination();
else:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
extract( shortcode_atts(array('show' =>''), $atts ));
extract( shortcode_atts(array('brand' =>''), $atts ));
$loop = new WP_Query( array(
'post_type' => 'auto',
'auto-brand' => $brand,
'paged' =>$paged,
'posts_per_page'=>$show,
'offset' => 0
));
while ($loop->have_posts()) : $loop->the_post();
?>
<div class="col-list-3">
<div class="featured-car-list">
<div class="featured-car-img">
<a alt="<?php echo get_the_title(); ?>" title="<?php echo get_the_title(); ?>" href="<?php the_permalink();?>">
<?php if(has_post_thumbnail()):
the_post_thumbnail('carforyou_small', array('class' => 'img-responsive'));
else:
echo "<div class='is-empty-img-box'></div>";
endif;
?>
</a>
<?php carforyou_AutoType(); ?>
<div class="compare_item">
<div class="checkbox">
<button id="compare_auto_btn" onclick="<?php echo esc_js('javascript:productCompare('.$post->ID.')'); ?>"><?php esc_html_e('Compare','carforyou'); ?></button>
</div>
</div>
</div>
<div class="featured-car-content">
<h6><a title="<?php echo get_the_title(); ?>" href="<?php the_permalink(); ?>"><?php $title = get_the_title(); echo mb_strimwidth($title, 0, 30, '...'); ?></a></h6>
<div class="price_info">
<?php if(!empty($post->DREAM_auto_price)): ?>
<p class="featured-price"><?php carforyou_curcy_prefix(); ?><?php echo number_format_i18n(esc_html($post->DREAM_auto_price)); ?></p>
<?php endif; ?>
<div class="car-location">
<?php $term_list = wp_get_post_terms($post->ID, 'auto-location', array("fields" => "all"));
foreach($term_list as $term_single)
$location = $term_single->name;
?>
<?php if(!empty($location)): ?>
<span><i class="fa fa-map-marker" aria-hidden="true"></i> <?php echo esc_html($location); ?> </span>
<?php endif; ?>
</div>
</div>
<ul>
<?php carforyou_featuredList(); ?>
</ul>
</div>
</div>
</div>
<?php endwhile;
carforyou_pagination();
endif;
}
?>
以上解决方案返回以下无法跟踪的错误代码:
PHP解析错误:语法错误,意外 位于“ else”(T_ELSE) /var/www/clients/clientxxx/webxxx/web/wp-content/themes/xxxxxx/functions/basic-functions.php 在第439行
第439行是“ else:”
<?php endwhile;
carforyou_pagination();
else:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
(...)
有什么建议吗?谢谢
答案 0 :(得分:1)
剥离HTML标记,很明显您的 if ... else 控件结构不正确。所讨论的 else 之前没有相应的 if 结构。
while ($loop->have_posts()) : $loop->the_post();
global $paged, $post;?>
<?php if(has_post_thumbnail()): //OPEN IF ONE
the_post_thumbnail('carforyou_small', array('class' => 'img-responsive'));
else:
echo "<div class='is-empty-img-box'></div>";
endif; //CLOSE IF ONE
?>
<?php carforyou_AutoType(); ?>
<?php if(!empty($post->DREAM_auto_price)): ?> //OPEN IF TWO
<?php endif; ?> //CLOSE IF TWO
<?php $term_list = wp_get_post_terms($post->ID, 'auto-location', array("fields" => "all"));
foreach($term_list as $term_single)
$location = $term_single->name;
?>
<?php if(!empty($location)): ?> //OPEN IF THREE
<?php endif; ?> //CLOSE IF THREE
<?php carforyou_featuredList(); ?>
<?php endwhile;
carforyou_pagination();
else: //SO WHERE IS IF FOUR???
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
extract( shortcode_atts(array('show' =>''), $atts ));
...