В принципе у меня есть два типа сообщений, «Собака» и «Кошка». У меня есть шаблон страницы с двумя циклами WP_Query, отображающими два последних сообщения из каждого типа сообщения в каждом цикле. Ниже, как я регистрация типов сообщения:Несколько WP_Query с пользовательским типом сообщения и разбиением на страницы
<?php
function cat_post_type() {
register_post_type('cat',
array('labels' => array(
'name' => __('Cats', 'bonestheme'),
'singular_name' => __('Cat', 'bonestheme'),
'all_items' => __('All Cats', 'bonestheme'),
'add_new' => __('Add New', 'bonestheme'),
'add_new_item' => __('Add New Cat', 'bonestheme'),
'edit' => __('Edit', 'bonestheme'),
'edit_item' => __('Edit Cats', 'bonestheme'),
'new_item' => __('New Cat', 'bonestheme'),
'view_item' => __('View Cat', 'bonestheme'),
'search_items' => __('Search Cat', 'bonestheme'),
'not_found' => __('Nothing found in the Database.', 'bonestheme'),
'not_found_in_trash' => __('Nothing found in Trash', 'bonestheme'),
'parent_item_colon' => ''
),
'description' => __('This is the cat post type', 'bonestheme'),
'public' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'show_ui' => true,
'query_var' => true,
'menu_position' => 8,
'rewrite' => array('slug' => 'cat', 'with_front' => false),
'has_archive' => 'cats',
'capability_type' => 'post',
'hierarchical' => false,
'supports' => array('title', 'editor', 'thumbnail')
)
);
}
add_action('init', 'cat_post_type');
function dog_post_type() {
register_post_type('dog',
array('labels' => array(
'name' => __('Dogs', 'bonestheme'),
'singular_name' => __('Dog', 'bonestheme'),
'all_items' => __('All Dogs', 'bonestheme'),
'add_new' => __('Add New', 'bonestheme'),
'add_new_item' => __('Add New Dog', 'bonestheme'),
'edit' => __('Edit', 'bonestheme'),
'edit_item' => __('Edit Dogs', 'bonestheme'),
'new_item' => __('New Dog', 'bonestheme'),
'view_item' => __('View Dog', 'bonestheme'),
'search_items' => __('Search Dog', 'bonestheme'),
'not_found' => __('Nothing found in the Database.', 'bonestheme'),
'not_found_in_trash' => __('Nothing found in Trash', 'bonestheme'),
'parent_item_colon' => ''
),
'description' => __('This is the dog post type', 'bonestheme'),
'public' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'show_ui' => true,
'query_var' => true,
'menu_position' => 8,
'rewrite' => array('slug' => 'dog', 'with_front' => false),
'has_archive' => 'dogs',
'capability_type' => 'post',
'hierarchical' => false,
'supports' => array('title', 'editor', 'thumbnail')
)
);
}
add_action('init', 'dog_post_type');
?>
и ниже, как я отображая типы сообщения:
<?php
$cat_query = new WP_Query(
array(
'posts_per_page' => 2,
'post_type' => 'cat'
)
);
if($cat_query->have_posts()) :
?>
<div>
<?php
while($cat_query->have_posts()) :
$cat_query->the_post();
?>
<div>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</div>
<?php
endwhile;
wp_reset_postdata();
?>
</div>
<?php endif; ?>
<?php
$dog_query = new WP_Query(
array(
'posts_per_page' => 2,
'post_type' => 'dog'
)
);
if($dog_query->have_posts()) :
?>
<div>
<?php
while($dog_query->have_posts()) :
$dog_query->the_post();
?>
<div>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</div>
<?php
endwhile;
wp_reset_postdata();
?>
</div>
<?php endif; ?>
Я хочу, чтобы иметь возможность сосуществовать со своей пагинацией , очень похоже на here (watch the video), но это похоже на работу только с обычными сообщениями WP, а не с пользовательскими типами сообщений. Если кто-нибудь знает, как достичь этого, это было бы удивительно, потому что это сводит меня с ума!
EDIT
Я почти достиг этого с помощью следующего кода, но он ошибочен, к примеру, если я иду на третьей странице на обоих вёрстка, затем нажмите страницу один на кота после типа пагинацией , он будет идти к тому же URL это уже:
<?php
$paged1 = isset($_GET['paged1']) ? (int) $_GET['paged1'] : 1;
$cat_query = new WP_Query(
array(
'posts_per_page' => 2,
'post_type' => 'cat',
'paged' => $paged1
)
);
if($cat_query->have_posts()) :
?>
<div>
<?php
while($cat_query->have_posts()) :
$cat_query->the_post();
?>
<div>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</div>
<?php
endwhile;
echo paginate_links(
array(
'format' => '?paged1=%#%',
'current' => $paged1,
'total' => $cat_query->max_num_pages,
'add_args' => array('paged2' => $paged2)
)
);
wp_reset_postdata();
?>
</div>
<?php endif; ?>
<?php
$paged2 = isset($_GET['paged2']) ? (int) $_GET['paged2'] : 1;
$dog_query = new WP_Query(
array(
'posts_per_page' => 2,
'post_type' => 'dog',
'paged' => $paged2
)
);
if($dog_query->have_posts()) :
?>
<div>
<?php
while($dog_query->have_posts()) :
$dog_query->the_post();
?>
<div>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</div>
<?php
endwhile;
echo paginate_links(
array(
'format' => '?paged2=%#%',
'current' => $paged2,
'total' => $dog_query->max_num_pages,
'add_args' => array('paged1' => $paged1)
)
);
wp_reset_postdata();
?>
</div>
<?php endif; ?>
Благодарим за это, но ознакомьтесь с обновлением редактирования исходного сообщения. – Tom
@ Вы поменяли '' add_args '=> массив (' paged1 '=> $ paged1) 'ваших пользовательских postypes –
Смотрите мой обновленный ответ –