从Wordpress我获得每页帖子数$posts_per_page
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' );
答案 0 :(得分:0)
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