Код: Выделить всё
function add_scripts_styles($hook) {
wp_enqueue_script('my_js_file', get_template_directory_uri(). '/assets/js/main.js', array('jquery'), 1);
wp_localize_script('my_js_file', 'ajax_details', array(
'ajax_url' => admin_url('admin.ajax.php'),
'nonce' => wp_create_nonce('my_nonce'),
));
}
add_action("wp_enqueue_scripts","add_scripts_styles");
function do_this(){
$post_id = intval($_POST['post_id']);
ob_start();
echo "Hello World";
$out = ob_get_clean();
$out = strtolower($out);
var_dump($out);
}
add_action("wp_ajax_do_this","do_this");
add_action("wp_ajax_nopriv_do_this","do_this");
Код: Выделить всё
document.addEventListener('DOMContentLoaded', () => {
const cards = document.querySelectorAll('[id^=tagged]');
function open(){
document.querySelector('.sidebar').style.width = "25%";
}
function close(){
document.querySelector('.sidebar').style.width = "0";
}
cards.forEach(card => {
card.addEventListener('click', e => {
open();
var id_post = e.currentTarget.getAttribute('data-post_ID');
console.log(id_post);
jQuery.ajax({
type: "post",
url: `${window.location.origin}/wp-admin/admin-ajax.php`,
data:{
action: "my_action",
post_id: id_post,
},
success: function(result) {
$('#pusha').html(result.data.html);
}
});
})
})
close();
})
Код: Выделить всё
[i][/i]
let cBtn =document.getElementById('closed');
cBtn.addEventListener('click', e=> {
document.querySelector('.sidebar').style.width = "0";
})
Подробнее здесь: https://stackoverflow.com/questions/790 ... equest-400
Мобильная версия