Я два таможенных постов типа:постраничного таможенного пост типа в одной странице WordPress
School
teacher
и там соединяются с помощью сообщения 2 сообщения плагин. поэтому, когда я показываю одну страницу школы school-single.php,
, она показывает мне информацию о школе и список учителей, работающих в этой школе. все работает отлично. для меня Я хочу показать список учителей по разбивке на страницы, и это не работает.
Регистрация ТАМОЖЕННЫЙ ПОСТ Тип
function school() {
$labels = array(
'name' => _x('schools', 'Post Type General Name', 'text_domain'),
'singular_name' => _x('school', 'Post Type Singular Name', 'text_domain'),
'menu_name' => __('school', 'text_domain'),
'name_admin_bar' => __('school', 'text_domain'),
'parent_item_colon' => __('Parent Item:', 'text_domain'),
'all_items' => __('All Items', 'text_domain'),
'add_new_item' => __('Add New Item', 'text_domain'),
'add_new' => __('Add New', 'text_domain'),
'new_item' => __('New Item', 'text_domain'),
'edit_item' => __('Edit Item', 'text_domain'),
'update_item' => __('Update Item', 'text_domain'),
'view_item' => __('View Item', 'text_domain'),
'search_items' => __('Search Item', 'text_domain'),
'not_found' => __('Not found', 'text_domain'),
'not_found_in_trash' => __('Not found in Trash', 'text_domain'),
'items_list' => __('Items list', 'text_domain'),
'items_list_navigation' => __('Items list navigation', 'text_domain'),
'filter_items_list' => __('Filter items list', 'text_domain'),
);
$args = array(
'label' => __('school', 'text_domain'),
'description' => __('school Description', 'text_domain'),
'labels' => $labels,
'supports' => array('title', 'editor',),
'taxonomies' => array('category', 'post_tag'),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
);
register_post_type('school', $args);
}
add_action('init', 'school', 0);
код Разбивка: По wp_bs_pagination
<?php
/**
* WordPress Bootstrap Pagination
*/
add_action('wp_loaded', 'the_pagination');
// Bootstrap pagination function
function the_pagination($pages = '', $range = 1) {
$showitems = ($range * 2) + 1;
global $paged;
if(empty($paged)) $paged = 1;
if($pages == '') {
global $wp_query;
$pages = $wp_query->max_num_pages;
if(!$pages) {
$pages = 1;
}
}
if(1 != $pages) {
echo '<div class="text-center">';
echo '<nav><ul class="pagination"><li class="disabled hidden-xs"><span><span aria-hidden="true">Page '.$paged.' of '.$pages.'</span></span></li>';
if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<li><a href='".get_pagenum_link(1)."' aria-label='First'>«<span class='hidden-xs'> First</span></a></li>";
if($paged > 1 && $showitems < $pages) echo "<li><a href='".get_pagenum_link($paged - 1)."' aria-label='Previous'>‹<span class='hidden-xs'> Previous</span></a></li>";
for ($i=1; $i <= $pages; $i++) {
if (1 != $pages &&(!($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems)) {
echo ($paged == $i)? "<li class=\"active\"><span>".$i." <span class=\"sr-only\">(current)</span></span>
</li>":"<li><a href='".get_pagenum_link($i)."'>".$i."</a></li>";
}
}
if ($paged < $pages && $showitems < $pages) echo "<li><a href=\"".get_pagenum_link($paged + 1)."\" aria-label='Next'><span class='hidden-xs'>Next </span>›</a></li>";
if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<li><a href='".get_pagenum_link($pages)."' aria-label='Last'><span class='hidden-xs'>Last </span>»</a></li>";
echo "</ul></nav>";
echo "</div>";
}
}
Запрос, список учителей в школе-single.php
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$connected = new WP_Query(array(
'connected_type' => 'school-teacher',
'connected_items' => get_queried_object_id(),
'nopaging' => false,
'posts_per_page' => 1,
'paged' => $paged,
),
));
if ($connected->have_posts()) :
while ($connected->have_posts()) : $connected->the_post();
....
endwhile;
endif;
/* Pagination */
the_pagination($connected->max_num_pages);
/* Restore original Post Data */
wp_reset_postdata();
пагинацию отображается правильно:
URL-адрес страницы 2 является: wwww.mywebsite.com/school/school_name/page/2
, когда я нажимаю на него перенаправляют меня же странице. wwww.mywebsite.com/school/school_name
.
Я думаю, что единственная страница не принимает параметр в URL-адресе. В любом случае кто-то может предложить решение!