1

我正在创建一个排序页面,它将显示数据库的内容,用户可以使用 listjs 对其进行排序。问题是当我按下任何按钮时,从数据库加载的内容就会消失。当我手动填充内容时,效果很好。有人可以帮我解决这个问题吗?

我的加载功能:

$(document).ready(function(){
     $(".list").load("../wp-content/php/sorting.php");
});

排序.php

<?php
mysql_connect("***", "***", "**") or die(mysql_error());
mysql_select_db("***");

$result = mysql_query("SELECT * FROM business");

while($row = mysql_fetch_array($result))
  {
 ?><li class="onebusiness"><a href="<?php
  echo $row['link'];?>"><img src="<?php
  echo $row['img'];?>" height="125" width="125"/><p class="name"><?php
  echo $row['name'];?></p><p class="category" style="display:none;"><?php
  echo $row['category'];?></p></a></li><?php
  }
mysql_close();
?> 

HTML:

<script src="../wp-content/js/filter/call-php.js" type="text/javascript"></script>
<script src="../wp-content/js/list/list-min.js" type="text/javascript"></script>
<div id="busineseslist">
    <input class="search" placeholder="Search Business" />
    <ul class="sort-by">
        <li class="sort btn" data-sort="name">Sort by name</li>
        <li class="sort btn" data-sort="category">Sort by category</li>
    </ul>
    <ul class="filter">
        <li class="btn" id="filter-none">Show all</li>
        <li class="btn" id="filter-something">Only show something</li>
        <li class="btn" id="filter-else">Only show something else</li>
    </ul>
    <div class="list"></div>
</div>
4

1 回答 1

0

为什么你不这样做:

<script src="../wp-content/js/filter/call-php.js" type="text/javascript"></script>
<script src="../wp-content/js/list/list-min.js" type="text/javascript"></script>
<div id="busineseslist">
<input class="search" placeholder="Search Business" />
<ul class="sort-by">
    <li class="sort btn" data-sort="name">Sort by name</li>
    <li class="sort btn" data-sort="category">Sort by category</li>
</ul>
<ul class="filter">
    <li class="btn" id="filter-none">Show all</li>
    <li class="btn" id="filter-something">Only show something</li>
    <li class="btn" id="filter-else">Only show something else</li>
</ul>
<div class="list"><?php include '../wp-content/php/sorting.php'; ?></div>
</div>

有了这个,你可以删除这一行:

<script src="../wp-content/js/filter/call-php.js" type="text/javascript"></script>//delete this

我认为它的 js 具有以下代码:

$(document).ready(function(){
 $(".list").load("../wp-content/php/sorting.php");
});

因为使用 php 包含您不需要加载功能;)

------------------------已编辑------------- ---------------

在 wordpress 中,您可以通过以下方式包含文件:

将包含文件放在主题文件夹中,并在主题的 footer.php 中使用它:

 <?php include (TEMPLATEPATH . '/sorting.php'); ?> 

请参阅此参考链接: http: //www.deluxeblogtips.com/2010/06/wordpress-include-template-files.html

您的 div 应如下所示:

转到“主题编辑器”,查找生成 html 的文件。编辑它并将这段代码放在 divs 标签之间:

<div class="list"><?php include (TEMPLATEPATH . '/sorting.php'); ?></div> 

萨卢多斯。

于 2013-03-01T15:48:50.500 回答