Thread Starter
draver
(@draver)
Ok, i managed to load the content from the first page using AJAX but i’m stuck at a point.
This is the javascript
var $j = jQuery.noConflict();
$j(function(){
var page = 1;
var max_page= 0;
if (page=1){$j("#new").hide();}
$j("#content").load("lorem-ipsum/page/"+page);
$j("#old").click(function(){
page = page+1;
$j("#content")
.fadeOut("slow")
.load("lorem-ipsum/page/"+page, function() {
$j(this).fadeIn("slow");
if (page >0){$j("#new").show()}
else {$j("#new").show();}
max_page = page;
});
return false;
});
$j("#new").click(function(){
page = max_page-1;
$j("#content")
.fadeOut("slow")
.load("lorem-ipsum/page/"+page, function() {
$j(this).fadeIn("slow");
});
return false;
});
});
});
And this is the navigation (located in the header.php):
<a href="#">Old Posts</a>
<a href="#">New Posts</a>
The “lorem-ipsum” page it’s just a template in wich are displayed the last 5 posts.
My problem is here: when the user is on the last page with the posts and there are no “old posts”, i want to make it to disappear. For the “next posts” was simple.
So my question is: how can i count the number of post and us the array in the javascript?
Thread Starter
draver
(@draver)
Ok, i figured out how to do it. This is the final code from header.php
<script>
$(function(){
var maxpage = new Array("<?php echo $wp_query->max_num_pages; ?>");
var nr = 0;
var page = 1;
$("#new").hide();
$("#content").load("lorem-ipsum/page/"+page);
$("#old").click(function(){
page = page+1;
$("#content")
.fadeOut("normal")
.load("lorem-ipsum/page/"+page, function() {
$(this).fadeIn("normal");
nr = nr +1;
if (page > 1){$("#new").show();}else{$("#new").hide();}
if (page < maxpage){$("#old").show();}else{$("#old").hide();}
});
return false;
});
$("#new").click(function(){
page=nr;
$("#content")
.fadeOut("normal")
.load("lorem-ipsum/page/"+page, function() {
$(this).fadeIn("normal");
if(page > 1){$("#new").show();} else{$("#new").hide();}
if (page < maxpage){$("#old").show();}else{$("#old").hide();}
nr=nr-1;
});
return false;
});
});
</script>
Thanks for support…
hello!
could you post the full code
how to use this function?
“could you post the full code. how to use this function?” – same question. I really need it right now. I’m doing ajax web project.