如何获取function.php文件中每页文章的数量值?
从WordPress的我得到的每$posts_per_page
如何获取function.php文件中每页文章的数量值?
global $wp_query; $args = array(
'post_type' => 'post',
'category_name' => $categories,
'posts_per_page' => $posts_per_page,
);
$posts = new WP_Query($args);
页的帖子数量数据如何现在得到的functions.php这个数字?
wp_register_script('loadmore', get_stylesheet_directory_uri() . '/assets/scripts/load-more.js', '', '', true); wp_localize_script('loadmore', 'loadmore_params', array(
'ajaxurl' => admin_url('admin-ajax.php'),
'posts' => $wp_query->query_vars,
'current_page' => get_query_var('paged') ? get_query_var('paged') : 1,
'max_page' => $posts_per_page,
));
wp_enqueue_script('loadmore');
回答:
function.php
function custom_posts_per_page($query) { if (is_home()) {
$query->set('posts_per_page', $posts_per_page);
}
if (is_search()) {
$query->set('posts_per_page', $posts_per_page);
}
if (is_archive()) {
$query->set('posts_per_page', $posts_per_page);
} //endif
} //function
以上是 如何获取function.php文件中每页文章的数量值? 的全部内容, 来源链接: utcz.com/qa/265550.html