我正在尝试查看我的短代码中的分页,所有页面都显示正常,并且点击相关页面也会显示该页面网址,但页面数据永远不会更改为该页面,它始终保持相同并且我的投资组合帖子总是一样的....这是我的整个代码,请任何人帮我解决这个问题。
$args = array(
'post_type' => 'portfolio',
'post_status' => 'publish',
'orderby' => 'date',
'order' => 'DESC',
'posts_per_page' => $num_posts,
);
$push_args = array_slice($args, 0, 2, true) + $stack + $stack_cat_all + array_slice($args, 2, count($args) - 1, true) ;
query_posts($push_args);
if($show_title == 'yes'){
$output = '<div class="section-title">';
$output .= '<h3>'.$element_title.'</h3>';
$output .= '<small>'.$element_caption.'</small>';
$output .= '</div>';
}
global $paged;
if ( get_query_var('paged') ) {
$paged = get_query_var('paged');
} else if ( get_query_var('page') ) {
$paged = get_query_var('page');
} else {$paged = 1;}
$args = array (
'post_type' => 'portfolio',
'posts_per_page' => $num_posts,
'post_status' => 'publish',
'paged' => $paged
);
$gallery_posts = new WP_Query($args);
if ( !empty($gallery_posts) ) {
if ($gallery_posts->have_posts()) {
while ($gallery_posts->have_posts()) {
$gallery_posts->the_post();
$terms = get_the_terms($post->ID, 'portfolio_category');
$links = array();
if (is_array($terms) || is_object($terms)) {
foreach ($terms as $term) {
$links[] = $term->name;
}
}
$links = str_replace(' ', '-', $links);
$tax = join(" ", $links);
$output .= '<div class="element-item ' . $tax . ' ' . $post_cols . '" data-category="transition">';
if ($thumbnail_position != 'below_title') {
if ($pretty_photo != 'no') {
$output .= '<a href="' . $post_image = wp_get_attachment_url(get_post_thumbnail_id($post->ID)) . '" rel="prettyPhoto[gallery1]"><img src="' . $post_image = wp_get_attachment_url(get_post_thumbnail_id($post->ID)) . '"></a>';
} else {
$output .= '<a href="' . $post->guid . '"><img src="' . $post_image = wp_get_attachment_url(get_post_thumbnail_id($post->ID)) . '"></a>';
}
}
if ($show_post_title != 'no') {
$output .= '<h3><a href="' . get_the_permalink() . '">' . get_the_title() . '</a></h3>';
}
if ($show_description != 'no') {
$output .= '<p>' . $content = substr(get_the_content(), 0, $num_characters) . '</p>';
}
if ($thumbnail_position == 'below_title') {
if ($pretty_photo != 'no') {
$output .= '<a href="' . $post_image = wp_get_attachment_url(get_post_thumbnail_id($post->ID)) . '" rel="prettyPhoto[gallery1]"><img src="' . $post_image = wp_get_attachment_url(get_post_thumbnail_id($post->ID)) . '"></a>';
} else {
$output .= '<a href="' . get_the_permalink() . '"><img src="' . $post_image = wp_get_attachment_url(get_post_thumbnail_id($post->ID)) . '"></a>';
}
}
if ($read_more != '') {
$read_more = $read_more;
} else {
$read_more = 'Read More';
}
if (($show_post_title != 'no') && ($show_description != 'no')) {
$output .= '<a href="' . get_the_permalink() . '">' . $read_more . '</a>';
}
$output .= '</div>';
}
$output .= '</div>';
//$output .= paginate_links( $args );
if($show_pagination != 'no') {
$big = 999999999;
$output .= '<div class="portfolio-pagination">' . paginate_links(array(
'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
'format' => '?paged=%#%',
'current' => max(1, get_query_var('paged')),
'total' => $gallery_posts->max_num_pages
));
$output .= '</div>';
}
wp_reset_query();
wp_reset_postdata();
return $output;
}
}}
它真的让我感到害怕,因为我现在浪费了3个小时:(
答案 0 :(得分:0)
是的,问题是您的错误代码,双重查询用法。只需评论此代码
$args = array(
'post_type' => 'portfolio',
'post_status' => 'publish',
'orderby' => 'date',
'order' => 'DESC',
'posts_per_page' => $num_posts,
);
$push_args = array_slice($args, 0, 2, true) + $stack + $stack_cat_all + array_slice($args, 2, count($args) - 1, true) ;
query_posts($push_args);
它与您的代码冲突,您的$ paged变量不知道该怎么办? 希望解决问题...