Thanks 😊 I would really like to add that feature but I’m currently swamped with client work atm. I originally wanted to do that but this plugin isn’t meant to replace all your pagination needs since it’s not SEO. Google won’t be able to find your stuff and if it does it will think you have duplicate page titles which is also bad. I made this for a small section of your website where you want to show non-important data or want to scroll through a calendar or something. But on the bright side, I do have a plan to re-write this to be SEO friendly 😉. All in good time!
Hi Cody,
Great plugin! Unfortunately, i’m having trouble getting it to work. I’m able to view the first “page” of entries, and the “next >>” link shows, but the “next >>” link isn’t functional. Clicking it does nothing.
Any ideas? Here’s my “ajax_template” code:
{exp:ajax_pagination weblog="videos" limit="9" template="{site_url}commercial5/ajax_template" holder="items" parse="inward"}
{prev_link} {if prev_link && next_link}|{/if} {next_link}
{exp:weblog:entries weblog="videos" disable="pagination|member_data|trackbacks" limit="{limit}" offset="{offset}" dynamic="off" }
// weblog entry content here //
{/exp:weblog:entries}
{/exp:ajax_pagination}
I really appreciate the help! I can PM you the URL if you need to look at it.
Plasmajam, ya, I’ll need a link to see what you are doing. Are you using anything else with jQuery that might be interfering? Are you sure you are including jQuery correctly?
I am having the exact same issue as Plasmajam.
Here is a link to my site.
Thanks!
Plasmajam, ya, I’ll need a link to see what you are doing. Are you using anything else with jQuery that might be interfering? Are you sure you are including jQuery correctly?I am having the exact same issue as Plasmajam. Here is a link to my site. Thanks!
Greetings bmschaaf,
I see your problem, if you look at the source code, specifically the jquery part, you’ll see that it’s getting your URL to your ajax_template wrong. It’s missing the ‘index.php’ part of it. It looks like you’ve erased the name of your sites index file when you haven’t used an .htaccess file for it to work. I think if you go back to: CP Home › Admin › System Preferences › General Configuration and fill in ‘index.php’ for your sites index file, this should work just fine for you 😉.
Best Regards, cody
this should work just fine for you 😉.
Thanks, Cody. You were correct. The address was incorrect. So, my test page worked great.
The next step was trying to get this to work in my real setup…which is quite a bit more complicated (naturally).
To start, I have a page with a series of checkboxes, and depending on what gets checked, values are sent via url and I am using ajax load to get the page. So, I may have a url that reads “***/index.php/research/get/dorsey/29/article”. Then, on that EE template I have some PHP code that reads that url and plugs in the values into the correct weblog entry parameters. Its on this page that I want my pagination code. (I will then pull this whole page over to the page with checkboxes, as I stated above)
So, my pagination code looks like this
<div id="ajax-text">
{exp:ajax_pagination weblog="research" limit="2" template="{site_url}index.php/research/get" holder="ajax-test" parse="inward"}
{prev_link} {if prev_link && next_link}|{/if} {next_link}
{exp:weblog:entries weblog="research" entry_id="not 38" category="<?php echo $myCategory; ?>" dynamic="off" search:authors="<?php echo $myAuthor; ?>" search:publication-type="<?php echo $myPubtype; ?>" limit="{limit}" offset="{offset}"}
<div><a href="http://{homepage}/{segment_1}/project/{url_title}">{title}</a>. {if authors}{authors backspace="2"}{au-first-name} {au-last-name}, {/authors}.{/if} {if publish-note}{publish-note}, {/if}{if publication-year}{publication-year}{/if}.</div>
{/exp:weblog:entries}
{/exp:ajax_pagination}
</div>
My problem appears to be with the ajax load url. Because, as I stated above, I use the url (segments) to build my weblog search.
FWIW, here is my php code…
<?php
$fullURL = $_SERVER['REQUEST_URI'];
$urlArray = split('\/', $fullURL);
$authorURL = $urlArray[(count($urlArray) - 3)];
$categoryURL = $urlArray[(count($urlArray) - 2)];
$pubtypeURL = $urlArray[(count($urlArray) - 1)];
$myAuthor = str_replace("-", "|", $authorURL);
$myCategory = str_replace("-", "|", $categoryURL);
$myPubtype = str_replace("-", "|", $pubtypeURL);
?>
Do you have any suggestions, Cody? Will I have to hack the plug-in to accept my full url? Or do you think I need to ditch the ajax pagination idea all together?
Thanks a ton for even reading this, I appreciate it!
Greeings again bmschaaf 😊,
First of all, I’d suggest you should tap into the EE Input class utilizing the SEGS method to grab your URI Segments, it’s a bit easier than what you are currently doing 😊. You can read about it here.
So I’m guessing that the first page shows up just fine with the correct entries but when you click next you lose your search parameters? I’m not sure this is going to work for your since it’s looking for certain parameters in the url itself. When you click the next button it passes the offset values to the plugin through the URL.
What I’ll do is have a look at rewriting this so it won’t depend on that functionality. It would make this more efficient as well.
Not sure when I’ll have time to do this, but we’ll see 😊.
UPDATE: I ended up using a plain ole jquery pagination plugin, and dig the results. I can get away with this, because I am not dealing with tons and tons of results. I will still be looking for updates here, out of curiosity.
Greetings again bmschaaf 😊,
Heya Cody. Nice to hear from you again. 😊
So I’m guessing that the first page shows up just fine with the correct entries but when you click next you lose your search parameters? I’m not sure this is going to work for your since it’s looking for certain parameters in the url itself. When you click the next button it passes the offset values to the plugin through the URL.
Correct. I tried passing the entire url through your plugin, by editing line 117 and 121. But, that didn’t work.
What I’ll do is have a look at rewriting this so it won’t depend on that functionality. It would make this more efficient as well. Not sure when I’ll have time to do this, but we’ll see 😊.
That would be lovely. Unfortunately, I have to get this project out the door. So, in the interim, I will just ditch pagination on this page. They don’t have a lot of content at the moment, so I will probably get away with it 😉
Thanks for helping me out Cody- you rock.
Great plugin! With the help of this tutorial I added a bit of jQuery code that allows some basic effects and a loading message. View source here:
http://www.allnighters.net/tst/ajx-pag/
It seems this plugin doesn’t work if you set multiple weblogs in the ajax_pagination tag.
e.g.
{exp:ajax_pagination weblog="weblog1|weblog2" limit="12" template="{site_url}includes/newsletter_pagination" holder="newsletter_thumbs" parse="inward"}
{if prev_link}<div class="paginate_prev">{prev_link}</div>{/if}
<ol id="newsletter_thumbs">
{exp:weblog:entries weblog="weblog1|weblog2" disable="pagination|member_data|trackbacks" limit="{limit}" offset="{offset}" dynamic="off"}
<li><a href="http://{url_title_path=center/newsletters}">{newsletter_image}</a>
<h4><a href="http://{url_title_path=center/newsletters}">{title}</a></h4></li>
{/exp:weblog:entries}
</ol>
{if next_link}<div class="paginate_next">{next_link}</div>{/if}
{/exp:ajax_pagination}
Thanks Cody, (almost) exactly what I was looking for.
I’ve tweaked the code a little to take into account a category tag. I wanted to paginate a weblog but limited to entries having a certain category. As my ajax_pagination was not looking for the category there was a mismatch between the ajax_pagination loop and the entries loop. Anyway, it’s a small modification to the DB query so thought I’d share it…just pass in category=”<category id list, comma separated>”
Get the extra tag param :
$category = ( ! $TMPL->fetch_param('category')) ? '' : $TMPL->fetch_param('category');
Updated db query, joining to the exp_category_posts table to restrict to the category_id passed into the plugin :
/* Query to check if the Next link is needed */
$sql = "SELECT a.weblog_id, b.title, cp.cat_id "
. "FROM exp_weblogs a JOIN exp_weblog_titles b on a.weblog_id = b.weblog_id "
. "LEFT OUTER JOIN exp_category_posts cp on b.entry_id = cp.entry_id "
. "WHERE a.blog_name = '" . $weblog . "' "
. "AND cp.cat_id > 0 ";
if ($category) {
//Limit to selected category if required
$sql .= " AND cp.cat_id in (" . $category . ") ";
}
$sql .= " LIMIT 1 "
. " OFFSET " . $future_offset;
$query = $DB->query($sql);
All entries seem to have an entry in exp_category_posts with cat_id = 0, I’m not sure why (still new to this!) so I excluded them to avoid double counting….
Seems to work OK for me - hopefully it’ll help someone out there…
Martin
One more little tweak. I’m using the ajax_pagination a few times on the same page (reading from different weblogs) so this was creating duplicate ID’s for the #next and #previous div’s used for the paging.
I just added two parameters “next_id” and “prev_id” to the ajax_pagination plugin, then modified the code to use these (if passed, otherwise default to next and previous) to name the div’s & to create the click handlers
You can then use the ajax_pagination multiple times on the same page by passing in unique ID names for each next_id and prev_id parameter.
//Added two input params:
...
$next_id = ( ! $TMPL->fetch_param('next_id')) ? 'next' : $TMPL->fetch_param('next_id');
$prev_id = ( ! $TMPL->fetch_param('prev_id')) ? 'previous' : $TMPL->fetch_param('prev_id');
...
//Modify the link builders:
$prev_link .= "\" class=\"" . $prev_class . "\" id=\"" . $prev_id . "\">" . $prev . "</a>";
$next_link .= "\" class=\"" . $next_class . "\" id=\"" . $next_id . "\">" . $next . "</a>";
//Use the variables to set up the click handler :
$(function() {
$('#<?= $next_id ?>').click(function(){
$("#<?= $holder ?>").load("<?= $template ?>/" + $("#<?= $next_id ?>").attr("rel"));
return false;
});
$('#<?= $prev_id ?>').click(function(){
$("#<?= $holder ?>").load("<?= $template ?>/" + $("#<?= $prev_id ?>").attr("rel"));
return false;
});
});
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.