我有一个wp_localize_script()
函数在我的函数中。php中,我需要将当前帖子的当前帖子ID推送到jQuery文件中。所以我想知道如何在我的函数中获取帖子的当前帖子ID。php。
这些都不起作用:
global $post;
$post_id = $post->ID;
global $wp_query;
$post_id = $wp_query->get_queried_object_id();
我有一个wp_localize_script()
函数在我的函数中。php中,我需要将当前帖子的当前帖子ID推送到jQuery文件中。所以我想知道如何在我的函数中获取帖子的当前帖子ID。php。
这些都不起作用:
global $post;
$post_id = $post->ID;
global $wp_query;
$post_id = $wp_query->get_queried_object_id();
如果将本地化脚本函数挂接到wp_enqueue_scripts
, 然后您将可以访问global $post
变量只要您在“wp”时或之后选择挂钩,您就应该可以访问global $post
.
<?php
add_action(\'wp_enqueue_scripts\', \'YOUR_NAME_scripts\');
function YOUR_NAME_scripts() {
wp_enqueue_script(\'YOUR_NAME-js\');
global $post;
$params = array(
\'site_url\' => site_url(),
\'admin_ajax_url\' => admin_url(\'admin-ajax.php\'),
\'post_id\' => $post->ID
);
wp_localize_script( \'jquery\', \'YOUR_NAME\', $params );
}
在带有JW Player(v5)的Wordpress(3.8.1)和JW插件(v2.1.2)中,我需要读取JWPlayer Plugin.通常情况下JWPlayer Plugin 工作原理如下,通过短代码:[jwplayer playlistid=\"1234\"] 。。然后aVideo Player 将与其中的播放列表一起呈现在页面上。我想做什么(定制)那么现在我该怎么做呢。。if i want to know (or pull out) the items inside a Playlist