带有“丑陋”和“漂亮”永久链接的分页链接?
1 个回答
- 投票数
因此,看起来可以使此函数与"丑陋"和"漂亮"的永久链接一起工作.这是代码:
<?php
global $wp_query;
//structure of "format" depends on whether we're using pretty permalinks
if( get_option('permalink_structure') ) {
$format = '?paged=%#%';
} else {
$format = 'page/%#%/';
}
$big = 999999999; // need an unlikely integer
$base = $format =='?paged=%#%' ? $base = str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ) : $base = @add_query_arg('paged','%#%');
echo paginate_links( array(
'base' => $base,
'format' => $format,
'current' => max( 1, $paged ),
'total' => $wp_query->max_num_pages,
'prev_text' => esc_html__( 'Prev', 'domain' ),
'next_text' => esc_html__( 'Next', 'domain' ),
'end_size' => 1,
'mid_size' => 1,
) );
?>
希望它将对某人有所帮助;)
So it look's like it is possible to make this function work with “ugly” and “pretty” permalinks. Here is the code:
<?php
global $wp_query;
//structure of "format" depends on whether we're using pretty permalinks
if( get_option('permalink_structure') ) {
$format = '?paged=%#%';
} else {
$format = 'page/%#%/';
}
$big = 999999999; // need an unlikely integer
$base = $format =='?paged=%#%' ? $base = str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ) : $base = @add_query_arg('paged','%#%');
echo paginate_links( array(
'base' => $base,
'format' => $format,
'current' => max( 1, $paged ),
'total' => $wp_query->max_num_pages,
'prev_text' => esc_html__( 'Prev', 'domain' ),
'next_text' => esc_html__( 'Next', 'domain' ),
'end_size' => 1,
'mid_size' => 1,
) );
?>
Hope it will help someone ;)
如果启用了"漂亮的"永久链接,我的代码将对静态页面有效(如果将页面设置为"主页"或"普通页面",则可以使用).但是,如果我使用"默认永久链接"结构,我的代码就会中断.
到目前为止(我与"漂亮的永久链接"配合很好,但与"丑陋的永久链接"配合使用了):
是否可以对(丑陋的和永久性的)永久链接进行分页?