我想在用户单击WordPress循环中的链接后显示帖子缩略图。
每篇文章都包含以下标记:
<span class="id_53">Display Post Image</span>
当用户单击此<span>
标记,我想使用AJAX显示后期缩略图图像$.post()
以下标记的内部:<div id="img_in"></div>
我想在用户单击WordPress循环中的链接后显示帖子缩略图。
每篇文章都包含以下标记:
<span class="id_53">Display Post Image</span>
当用户单击此<span>
标记,我想使用AJAX显示后期缩略图图像$.post()
以下标记的内部:<div id="img_in"></div>
你可以先试试这个。
1. 更改此<span class="id_53">Display Post Image</span>
至<span class="id_53" data-id="53">Display Post Image</span>
2. 创建您的js文件
$(function () { // click event example $(\'.id_53\').on(\'click\', getThumb); // call the ajax function getThumb() { $.post( \'http://path/wp-content/themes/your-theme/ajax-file.php\' , \'my_id=\'+$(this).attr(\'data-id\') , showThumb ); } // get image source function showThumb(e) { $(\'#img_in\').style({\'background-image\':e}); } });3. 创建ajax文件。php
// for external files include( \'../../../wp-load.php\' ); // get your variable $my_id = intval( $_POST[\'my_id\'] ); // get thumbnail ID $thumb_id = get_post_thumbnail_id( $my_id ); // get path of thumbnail $img = wp_get_attachment_image_src( $thumb_id, \'full\' ); echo $img[0];
我使用自定义ajax登录了我的站点。然后尝试连接我的wp管理员,页面会将我重定向到登录。phpphp中的自定义ajax函数;function ajax_login(){ check_ajax_referer( \'ajax-login-nonce\', \'security\' ); $info = array(); $info[\'user_login\'] = $_POST[\'username\']; $info[\'user_password\'] = $_POST