私は近いと思いますが、現時点では立ち往生しています。ここに少し背景があります。
私は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 コードで success 関数を使用するにはどうすればよいですか?