简体   繁体   中英

Wordpress - it works, but I don't know why

I'm writing a custom theme from scratch. As a menu, I use the jquery accordion control; each accordion item content is loaded using jquery.load(), as it follows:

function accordion_show(divID, cat){
        $("#" + divID).addClass("aLoaderShow");
        $("#" + divID).load("<?php bloginfo('url') ?>/wp-content/themes/peng2/menu-content.php?q=" + cat);
        $("#" + divID).show();
        $("#" + divID).removeClass("aLoaderShow");
    }

I have also enabled mod_rewrite to get pretty posts permalinks.

I can't understand why the script works only if I leave two blank lines at the top of menu-content.php.

I mean:

 <?php 
       $category = $_GET["q"];
       ...

it doesn't work. But:

(blank line)
(blank line) 
<?php 
       $category = $_GET["q"];
       ...

it works? It's a kind of magic?

Without knowing what you mean by "it works", it's impossible to give a full answer.

However, if I were to take a guess, I would say that the reason why you think it works with carriage returns is because the two carriage returns at the top of your file now means that the AJAX call receives data instead of nothing at all, which could be the original reason why it was not working.

This suggests something is wrong in your PHP script ie it's not echoing out the value it's supposed to. However, without being able to see what the rest of your PHP script does, I can't tell for certain.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM