Search code examples
expressionengine

Expression Engine limiting pagination and reverse related entries


I have an EE site running EE 1.7. It is a magazine site that has monthly "Editions", each edition may or may not have a book review in it. On the site, I need to list the book reviews, in reverse chronological order by edition. Here's my code:

{exp:weblog:entries weblog="editions" orderby="edition-date" sort="desc" disable="categories|member_data|trackbacks" limit="10" paginate="bottom"}
 {reverse_related_entries weblog="book-reviews"}
  ....

My problem is that the pagination is working based on the editions weblog, thus paging through editions that do NOT contain any book reviews. Thoughts?


Solution

  • A little tricky, you'll need to use an embed for this (or alternately you could create a small plugin to do this in a similar fashion).

    Try this setup in your template. Replace the weblog_ids in the query with your own (in this example, 1 is editions and 2 is book-reviews).

    {embed="embeds/reviews" entry_ids="{exp:query 
        sql="SELECT DISTINCT r.rel_child_id FROM exp_relationships r, exp_weblog_titles t  WHERE r.rel_parent_id  IN( SELECT entry_id  FROM exp_weblog_titles  WHERE weblog_id = 2 )  AND r.rel_child_id = t.entry_id  AND t.weblog_id = 1" 
        backspace="1"}{rel_child_id}|{/exp:query}"}
    

    Then, in embeds/reviews:

    {exp:weblog:entries weblog="editions" entry_id="{embed:entry_ids}" orderby="edition-date" sort="desc" disable="categories|member_data|trackbacks" limit="10" paginate="bottom"}
        {reverse_related_entries weblog="book-reviews"}
        ...