我对wordpress专利有问题。
每页的帖子(自定义类型帖子“属性”)限制为9。
当我pusblish 11属性时,分页链接工作正常。第一页中有9个属性,第二页中有2个属性。
但是,如果我发布了10个属性,那么第二页的链接就行不通了。它返回404错误。
循环代码:
<?php get_header(); ?>
<?php get_template_part( \'form_buscador\' ); ?>
<?php
$actualPagina = get_query_var( \'paged\' ) ? get_query_var( \'paged\' ) : 1;
$arrParamsProp = array(
\'post_type\' => \'propiedades\',
\'post_status\' => \'publish\',
\'posts_per_page\' => 9,
\'paged\' => $actualPagina
);
$propiedades = new WP_Query( $arrParamsProp );
?>
<main id="content" class="container">
<div class="row row-cols-1 row-cols-sm-2 row-cols-md-2 row-cols-lg-3 row-cols-xl-3">
<?php
if ( $propiedades->have_posts() ) {
while ( $propiedades->have_posts() ) {
$propiedades->the_post();
get_template_part( \'propiedad_card\' );
}
}
?>
</div>
</main>
<?php get_template_part( \'paginacion_prop\' ); ?>
<?php wp_reset_postdata(); ?>
<?php get_footer(); ?>
分页代码(pagination\\u prop):
<?php
global $propiedades;
$context = "";
//preg_match( \'/.*\\/archive-propiedades\\/.*/i\', get_pagenum_link( 1 ) )
if ( ! preg_match( \'/.*archive-propiedades.php.*/i\', $GLOBALS[\'template\'] ) ) {
$context = "propiedades/";
}
$actualPagina = get_query_var( \'paged\' ) ? get_query_var( \'paged\' ) : 1;
$argsPaginate = array(
\'base\' => get_pagenum_link( 1 ) . $context . \'%_%\',
\'type\' => \'array\',
\'total\' => $propiedades->max_num_pages,
\'format\' => \'page/%#%\',
\'current\' => $actualPagina,
\'prev_text\' => \'«\',
\'next_text\' => \'»\'
);
$arrPaginacion = paginate_links( $argsPaginate );
?>
<ul id="paginacion_pie" class="pagination justify-content-center my-3">
<?php
foreach ( $arrPaginacion as $item_pag ) {
$a_modified = preg_replace( \'/(.*class\\s*=\\s*.*)(page-numbers.*)/i\', \'${1}page-link ${2}\', $item_pag );
if ( preg_match( \'/.*class\\s*=\\s*.*(\\\'|\\").*current.*(\\\'|\\").*/i\', $item_pag ) ) {
?><li class="page-item disabled"><?php echo $a_modified; ?></li><?php
} else {
?><li class="page-item"><?php echo $a_modified; ?></li><?php
}
}
?>
</ul>
SO网友:Daniel Gross
我在一家房地产公司的网站上用了一些东西
你已经在使用引导了。但是,看看https://getbootstrap.com/docs/4.0/components/pagination/
在您的代码中,var$actualPagina=get\\u query\\u var之前的一行…
添加:
全球美元实际价格;
这就是你要做的。。。
代替
<?php get_template_part ( \'paginacion_prop\' );?>
根据
<?php thomas_pagination($propiedades->max_num_pages);?>
在您的功能中。php输入以下代码:
<?php
if( !function_exists(\'thomas_pagination\') ):
function thomas_pagination($pages = \'\', $range = 2) {
$showitems = ($range * 2)+1;
global $actualPagina;
if(empty($actualPagina)) $actualPagina = 1;
if($pages == \'\') {
global $wp_query;
$pages = $wp_query->max_num_pages;
if(!$pages)
{
$pages = 1;
}
}
if(1 != $pages) {
echo \'<ul class="pagination">\';
if($actualPagina > 2 && $actualPagina > $range+1 && $showitems < $pages) echo \'<li><a href="\' . esc_url(get_pagenum_link(1)) . \'"><span class="fa fa-angle-double-left"></span></a></li>\';
if($actualPagina > 1 && $showitems < $pages) echo \'<li><a href="\' . esc_url(get_pagenum_link($actualPagina - 1)) . \'"><span class="fa fa-angle-left"></span></a></li>\';
for ($i = 1; $i <= $pages; $i++) {
if (1 != $pages &&( !($i >= $actualPagina + $range + 1 || $i <= $actualPagina - $range - 1) || $pages <= $showitems )) {
echo ($actualPagina == $i)? \'<li class="active"><a href="#">\' . esc_html($i) . \'</a></li>\' : \'<li><a href="\' . esc_url(get_pagenum_link($i)) . \'">\' . esc_html($i) . \'</a></li>\';
}
}
if ($actualPagina < $pages && $showitems < $pages) echo \'<li><a href="\' . esc_url(get_pagenum_link($actualPagina + 1)) . \'" class="next"><span class="fa fa-angle-right"></span></a></li>\';
if ($actualPagina < $pages - 1 && $actualPagina + $range - 1 < $pages && $showitems < $pages) echo \'<li><a href="\' . esc_url(get_pagenum_link($pages)) . \'"><span class="fa fa-angle-double-right"></span></a></li>\';
echo \'</ul>\';
}
}
endif;
?>