【问题标题】:jqquery-ias in joomla doesn't workjoomla 中的 jquery-ias 不起作用
【发布时间】:2015-01-17 21:58:53
【问题描述】:

我在 joomla 3 中有一篇文章,其中包含这样的 php 代码:

<?php
include(config.php);
$limit = 10; #item per page
# db connect
$link = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die('Could not connect to MySQL DB ') .         mysql_error();
$db = mysql_select_db(DB_NAME, $link); 

$page = (int) (!isset($_GET['p'])) ? 1 : $_GET['p'];
# sql query
 $sql = "SELECT * FROM actor_info ORDER BY id DESC";
# find out query stat point
$start = ($page * $limit) - $limit;
# query for page navigation
if( mysql_num_rows(mysql_query($sql)) > ($page * $limit) ){
$next = ++$page;
}
 $query = mysql_query( $sql . " LIMIT {$start}, {$limit}");
if (mysql_num_rows($query) < 1) {
header('HTTP/1.0 404 Not Found');
echo 'Page not found!';
exit();
}
?>

<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="http://localhost/test/js/js/jquery-ias.min.js"></script>

<script type="text/javascript">
 $(document).ready(function() {
// Infinite Ajax Scroll configuration
jQuery.ias({
container : '#content', // main container where data goes to append
item: ".post",
pagination: "#content .navigation a",
next: ".next-posts a",
loader: '<img src="css/ajax-loader.gif"/>', // loading gif
triggerPageThreshold: 3 // show load more if scroll more than this
 });
});
</script>
</head>
<body>
<div class="wrap">
<h1><a href="#">Data load while scroll</a></h1>

 <!-- loop row data -->
<?php while ($row = mysql_fetch_array($query)): ?>
<div class="item" id="item-<?php echo $row['id']?>">
<h2>
<span class="num"><?php echo $row['id']?></span>
<span class="name"><?php echo $row['first_name'].' '.$row['last_name']?></span>
</h2>
<p><?php echo $row['film_info']?></p>
</div>
<?php endwhile?>

<!--page navigation-->
<?php if (isset($next)): ?>
<div class="nav">
 <div class="next-posts"><a href='test?p=<?php echo $next?>'>Next</a></div>
 </div>
<?php endif?>
 </div><!--.wrap-->
 </body>
</html>

现在它可以从数据库中检索数据,但是当我想获得滚动效果时,它会停止……所以它出现了一个链接“NEXT”,将我带到下一页 /test?p=2 等等

我该如何解决?

我通过一个名为 SOURCERER 的插件将这段代码放在一篇文章中

【问题讨论】:

    标签: php jquery css joomla pagination


    【解决方案1】:

    你做错了。

    混合代码和内容是不好的做法。但是在你的文章中混合老式的 php 简直是疯了。

    你试图违背框架而不是它。你让你的生活变得悲惨,你的代码丑陋且无法维护,你的网站容易受到攻击。每天你坚持这种方法,一只小猫就会死去。

    所以你想要无限滚动?很不错。您的代码可以工作,我不熟悉 IAS,但您需要将其移至其他位置(并且您需要迁移 mysql_connect 语句 - 您想使用 JDatabase)并更改初始化:

    <script type="text/javascript">
     $(document).ready(function() {
    

    <script type="text/javascript">
     jQuery(document).ready(function() {
    

    您的代码应该放在哪里?如果需要为您想要无限滚动到的每个页面重新调用它,您有多种选择:

    • 模板覆盖
    • 内容插件
    • 一个模块
    • 您可以调用的专用控制器
    • 以上的组合(即模板覆盖或用于初始调用的模块,用于下一页结果的控制器)

    模块可能是最简单的地方。您的模块将被放置在文章内容正下方的位置,并且在初始加载后,通过参数确定请求是否是第二页的请求,并且仅返回其标记(通过立即终止joomla处理它击中了模块)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多