我想我很接近,但我现在被困住了。这里有一点背景。
我正在使用 Wordpress,并且我有一个画廊插件。每个画廊都有一个 ID,当用户点击画廊链接时,我正在尝试完成,画廊将更改为相应的画廊。画廊的显示如下:
<?php echo do_shortcode('[slideshow gallery_id="1"]'); ?>
或者
<?php if (function_exists('slideshow')) { slideshow(true, "1", false, array()); } ?>
两者都做同样的事情-
wheregallery_id
指定正确的画廊。当用户单击链接时,我正在使用 AJAX 运行一些代码以获取正确的画廊 ID。
jQuery('.gallery-btn').click(function() {
var galleryId = jQuery(this).data('gallery');
jQuery.ajax({
url: "/wp-content/themes/thetheme/gallery.php",
data: {action: galleryId},
type: 'post',
success: function(output) {
console.log(output);
}
})
})
gallery.php 中的 PHP 代码:
<?php
if(isset($_POST['action']) && !empty($_POST['action'])) {
$galleryId = $_POST['action'];
passId($galleryId);
}
function passId($id) {
echo $id;
}
?>
output
返回我需要然后传递给 PHP 代码的 ID [slideshow gallery_id="$theID"]
。
如何output
在我的 PHP 代码中使用成功函数?