douhao2026 2015-01-26 07:57
浏览 55

PHP回显函数无法在使用jQuery .load动态加载的php页面中运行

Here is the index.php and desktop.php of my wordpress installation. I'm loading desktop.php into #tLoad if browser window width is larger than 800px. So far so good. But I want to load it with a php echo. And in the desktop.php I want to use etc, but it's not working either. I get an error that says "Fatal error: Call to undefined function.." and so on. I understand that I probably have to use AJAX calls of some kind, but I can't figure it out..

How can I make the php functions work inside the script and desktop.php?

<?php 
     /* Template Name: Start */
?>        
<?php get_header(); ?>

<script type="text/javascript">
    $(document).ready(function() {
        function o() {
            if (ww > 800) {
                if ($.browser.device == false) {
                    e.load(n);
                } else {
                    e.load(r);
                }
            } else if (ww < 800) {
                e.load(r);
            }
        }
        isHome = true;
        var e = $("#tLoad"),

        // This is the first php echo that's not working (I have to put in the direct url to make it work):          
        n = "<?php echo get_template_directory_uri(); ?>/desktop.php",
        r = "<?php echo get_template_directory_uri(); ?>/mobile_v.php";

        $(window).resize(function() {
            ww = win.width();
            o()
        });

        o()
    });
</script>

<div id="tLoad"></div>

<?php get_footer(); ?>

desktop.php:

<?php the_content(); ?>
  • 写回答

1条回答 默认 最新

  • duanjiagu0655 2015-01-26 08:09
    关注

    I get an error that says "Fatal error: Call to undefined function.."

    get_template_directory_uri() is located in wp-includes/theme.php. You have to make sure theme.php is included before you call the function. Use

    include_once "wp-includes/theme.php";
    

    before you make a call to get_template_directory_uri()

    评论

报告相同问题?

悬赏问题

  • ¥100 求数学坐标画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站