好吧,我在这个相当新手,但这里有云:Supersized.js你怎么称呼JSON编码数据放入设置脚本
我使用WordPress站点supersized.js创建完整尺寸的背景图片为头版幻灯片足以说剧本的设置及其工作现在我的下一个问题是使脚本使用wp_attachment
在我functions.php文件拉动图片我创造了这个:
// Get all of the images attached to the current post
// These images will be used in the Supersized homepage gallery
function supersized_get_images($size = 'full') {
global $post;
$photos = get_children(array('post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID'));
$results = array();
if ($photos) {
foreach ($photos as $photo) {
// get the correct URL for the selected size
$results['image'] = wp_get_attachment_url($photo->ID);
}
}
// encode into JSON format and pass to javascript supersettings.js
echo json_encode($results);
}
无论如何(我把echo
)因为我想看到它正在生成正确的JSON格式。回声上的输出如下所示:
{"image":"http:\/\/pilarcorrias.secondvariety.org\/wp-content\/uploads\/0bcf5aa159739b260a77758c7d33699b.jpg"}
这我假设是正确的。超大型有类似如下的设置文件:
jQuery(function($){
$.supersized({
//Functionality
slideshow : 1, //Slideshow on/off
autoplay : 1, //Slideshow starts playing automatically
start_slide : 1, //Start slide (0 is random)
random : 0, //Randomize slide order (Ignores start slide)
slide_interval : 3000, //Length between transitions
transition : 1, //0-None, 1-Fade, 2-Slide Top, 3-Slide Right, 4-Slide Bottom, 5-Slide Left, 6-Carousel Right, 7-Carousel Left
transition_speed : 500, //Speed of transition
new_window : 1, //Image links open in new window/tab
pause_hover : 0, //Pause slideshow on hover
keyboard_nav : 1, //Keyboard navigation on/off
performance : 1, //0-Normal, 1-Hybrid speed/quality, 2-Optimizes image quality, 3-Optimizes transition speed // (Only works for Firefox/IE, not Webkit)
image_protect : 1, //Disables image dragging and right click with Javascript
image_path : '/../../../slideshow/', //Default image path
//Size & Position
min_width : 0, //Min width allowed (in pixels)
min_height : 0, //Min height allowed (in pixels)
vertical_center : 1, //Vertically center background
horizontal_center : 1, //Horizontally center background
fit_portrait : 1, //Portrait images will not exceed browser height
fit_landscape : 0, //Landscape images will not exceed browser width
//Components
navigation : 1, //Slideshow controls on/off
thumbnail_navigation : 1, //Thumbnail navigation
slide_counter : 1, //Display slide numbers
slide_captions : 1, //Slide caption (Pull from "title" in slides array)
slides : [ //Slideshow Images
{image : 'http://buildinternet.s3.amazonaws.com/projects/supersized/3.1/slides/quietchaos-kitty.jpg', title : 'Quiet Chaos by Kitty Gallannaugh', url : 'http://www.nonsensesociety.com/2010/12/kitty-gallannaugh/'},
{image : 'http://buildinternet.s3.amazonaws.com/projects/supersized/3.1/slides/wanderers-kitty.jpg', title : 'Wanderers by Kitty Gallannaugh', url : 'http://www.nonsensesociety.com/2010/12/kitty-gallannaugh/'},
{image : 'http://buildinternet.s3.amazonaws.com/projects/supersized/3.1/slides/apple-kitty.jpg', title : 'Applewood by Kitty Gallannaugh', url : 'http://www.nonsensesociety.com/2010/12/kitty-gallannaugh/'}
]
});
});
在这个文件中的最后一行声明参数slides
,然后通过图像引用到幻灯片。现在我已经检查了幻灯片功能,并且没有URL和TITLE信息,这意味着我只需要给它image
对象,这里是文件URI,这意味着我的JSON位应该逐字运行。现在我知道我正确编码了PHP数组,我怎样才能将它放到上面的supersettings.js文件中......一直到处搜索,但没有找到解释它的东西,我可以用我的小脑袋来解释它。任何帮助将非常感激。
您也可以将数据从PHP加载到某些hdden输入中,然后使用.val()将其加载到插件中。这样你就不会混用JS和PHP。 – ogur 2012-01-30 01:14:59