wordpress页面中添加变量

当页面ajax请求时候,可能需要一些js变量。这些变量可以通过wordpress 内置函数提前渲染到页面中存储。以方便ajax请求时候,获取到参数。

wp_register_script( 'mts_ajax', get_template_directory_uri() . '/js/ajax.js', true );
wp_enqueue_script( 'mts_ajax' );
wp_localize_script(
	'mts_ajax',
	'mts_ajax_loadposts',
	array(
		'startPage' => $paged,
		'maxPages' => $max,
		'nextLink' => next_posts( $max, false ),
		'autoLoad' => $autoload,
		'i18n_loadmore' => __( 'Load more', 'coupon' ),
		'i18n_loading' => __('Loading...', 'coupon' ),
		'i18n_nomore' => __( 'No more posts.', 'coupon' )
	 )
);

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章