2016-07-22 91 views
0

我有我的WordPress插件后续:WordPress的插件显示的代码查询作为HTML文本

<body> 
    <h1>My example site</h1> 

    <?php 
     global $wpdb; 
     //require_once('../../../wp-load.php'); 

     $posts = $wpdb->get_results("SELECT * FROM red_reservacion;"); 

     foreach($posts as $row) 
     { 
     } 

    ?> 

</body> 

,在我.php文件。

但当页面呈现在浏览器中显示:

enter image description here

我认为这个问题是greater than symbol

存在的方式来解决这个问题?

+0

浏览器中的网址如何?它是否以'FILE:///'开头? – FirstOne

+0

[PHP代码未被执行,而是代码显示在页面上]的可能重复(http://stackoverflow.com/questions/5121495/php-code-is-not-being-executed-instead-code-shows-在页面上) – FirstOne

+0

@FirstOnethe'wp-load.php'已被注释 – MrMins

回答

0

假设您的short tags已关闭,因此PHP无法识别<?,顺便说一下,您也可以将所有PHP代码移动到脚本的顶部以查看是否有帮助...您可以试试相反:

<?php //<== JUST ADD php AFTER <? 

     //require_once('../../../wp-load.php'); 
     // DO ALL THE PHP OPERATIONS OUTSIDE THE HTML BLOCK 
     // PERHAPS AT THE VERY TOP OF YOUR SCRIPT TO SEE IF IT HELPS... 
     global $wpdb; 
     $posts = $wpdb->get_results("SELECT * FROM red_reservacion"); 
     $output = ""; 

     foreach($posts as $row){ 
      $output .= "<h2 class='h2-class'>{$row->post_title}</h2>" . PHP_EOL; 
      $output .= "<div class='div-class'>{$row->post_content}</div>" . PHP_EOL; 
      // CONTINUE BUILDING UP YOUR OUTPUT STRING HERE... 
     } 
    ?> 

     <body> 
      <h1>My example site</h1> 
      <?php echo $output; ?> 
     </body> 
+0

完全相同的问题 – MrMins

+0

@MrMins然后尝试移动HTML块外的所有PHP代码,然后查看是否有帮助。上面的代码已更新,以说明... – Poiz