小编Hyn*_*kal的帖子

Wordpress Ajax技术

我最近一直在玩AJAX到WordPress.我知道有很多插件可用,但我想自己制作.

在有关AJAXified WordPress的文章中,大多数人建议使用admin-ajax.php来处理AJAX请求.我的第一个想法是如何制作它只是创建自定义get_header()和get_footer()

第一路

// Boolean function ?ajax=true
function is_ajax () {
  if($_REQUEST['ajax']) {
    return true;
  } else {
    return false;
  }
}

function ajax_get_header () {
  if(is_ajax()) {
    get_header('ajax'); 
    /* Insert header-ajax.php which
    includes only google analytics tracking code and some minor stuff */
    return true;
  } else {
    get_header();  
    // Standard header
    return true;
  }
}

/* Function ajax_get_footer() pretty much the same */
Run Code Online (Sandbox Code Playgroud)

然后,页面模板看起来像

<?php ajax_get_header(); ?>

<!-- Content -->

<?php ajax_get_footer(); ?>
Run Code Online (Sandbox Code Playgroud)

当然,制作ajax是标准方式.这种方法让我觉得简单干净.另一方面,许多人建议使用内置函数,通过创建一个钩子来捕获AJAX调用.

第二种方式 …

php ajax wordpress jquery

5
推荐指数
1
解决办法
1189
查看次数

标签 统计

ajax ×1

jquery ×1

php ×1

wordpress ×1