Skip to content

Entry linking plugin for EE 2.x

16 Nov 2010

Entry linking plugin for EE 2.x

With this Plugin you can create next/previous entry links based on your own custom entries ordering:

{exp:entry_linking entry_id="{segment_2}" link="next" 
channel="my_channel" orderby="my_custom_field" sort="ASC" 
status="open" mode="short" no_results="cycle"}
<a href="{path=site/{link_entry_id}}">{link_title}</a>
{/exp:entry_linking} 

Parameters:
entry_id — the ‘start’ entry id to get next&prev links. REQUIRED.
link — type of link. Possible values are ‘next’ and ‘prev’. Defaults to ‘next’.
channel — channel name to look up entries. Separate multiple channels with pipe |. If not specified, will look in all channels
category — categoryname to look up entries. Separate multiple categories with pipe |. If not specified, will look in all categories
orderby — standard or custom field to biuld sorting. If not specified, defaults to entry_date.
sort — sorting order. ASC (default) or DESC.
status — status of entries to look up. Defaults to ‘open’. Separate multiple values with pipe |.
no_results — behaviour in case there is no next or previous link. Possible values are
    cycle — snow first entry for ‘next’ link, last entry for ‘prev’ link. This is default behaviour.
    empty — do not show the link if the are no results
mode — the returned data mode. Can be ‘short’ (default) - only standard entry fields returned (link_title, link_entry_id etc) or ‘full’ - all custom fields available as well.

Variables:
All returned variables (field names) will be prefixed with ‘link_’, e.g. {link_entry_id}, {link_my_custom_field} etc.
All field names available within exp_weblog_channels are available here (plus all custom fields if called in ‘full’ mode).

Conditionals:

{if no_next_link}...custom code or link ...{if:else}...regular code...{/if}
{if no_prev_link}
...custom code or link ...{if:else}...regular code...{/if} 


Note that plugin will not return any results if you have less that 3 entries.

Get the plugin by making a payment using button on sidebar or from Devot:ee

This is plugin for EE 2.x branch. The version for EE 1.x can be found here.

For support, please email .(JavaScript must be enabled to view this email address).

Changelog RSS

  • v. 2.0 — 2010-11-16 14:15
    • Initial release
  • v. 2.1 — 2011-03-30 11:20
    • Added filter by category
  • v. 2.3 — 2014-06-26 08:12
    • EE 2.8 compatibility release
  • v. 2.4 — 2014-12-08 12:32
    • Fixed bug with no_next_link/no_prev_link conditionals

Licensing & support terms

Comments

  1. oli
    oli 22 Nov 2010

    I am receiving a few php errors when trying to use this plugin in the following way

    ...[code removed]...

    I am using EE 2.1. The above doesn’t work at all when I use channel=“my-weblog”, instead of weblog=“my-weblog”

    The above works when there is no orderby used, then it goes through all the channels and entries available. The orderby above is a relationship field, but it also doesn’t work when I use title or any other custom field.

    Thank you for your assistance, if I can get this going it will really be a very useful plugin.

  2. Yuri Salimovskiy's avatar
    Yuri Salimovskiy 22 Nov 2010

    This error is fixed in 2.0.1 version.

  3. Yuri Salimovskiy's avatar
    Yuri Salimovskiy 22 Nov 2010

    I’m not sure however how the plugin will work with relationship field. Please let me know if anything will go wrong.

  4. Grzegorz Dobrzycki
    Grzegorz Dobrzycki 31 Jan 2011

    Hello,
    Does this plugin work with the static pages or with the Structure extension?

  5. Yuri Salimovskiy's avatar
    Yuri Salimovskiy 01 Feb 2011

    You need to provide entry_id as parameter to the plugin. It does not contain any specific checks for pages or structure extension in its current version (might add that in future)

  6. Leon
    Leon 03 Apr 2011

    Hi Yuriy,
    I’ve bought your plugin because I wanted to create prev/next links which follow the order set with Low Reorder. Works great! However, when I have only 2 entries, I still want to use prev/next links. On this page, you say “Note that plugin will not return any results if you have less that 3 entries.”

    Why is that? If I have two entries, I should still be able to navigate from one to the other by using a prev/next link?

    I think I’ve got it working by simply commenting 4 lines in your code, but I’m just wondering what the reason is as I don’t want to break the functionality of this plugin with the 4 commented lines?

    Thanks!
    Leon

  7. Yuri Salimovskiy's avatar
    Yuri Salimovskiy 03 Apr 2011

    Hi Leon,
    The reason for this limit is that you need to have more than 1 item to build prev/next links, and 3 is number when prev and next links will not be duplicates. The info on this page is a bit out-of date however (will update it soon) and currently only 2 entries are required.

  8. edward
    edward 09 Jun 2011

    Hi,
    Do you know if this plugin works with Channel Images? I’ve got a photo gallery that I’m trying to do some conditionals when I reach the final image and so would love to use this, but I’m a little lost on how to go about it.

    • Yuri Salimovskiy's avatar
      Yuri Salimovskiy 09 Jun 2011

      Hi Edward,
      no, it works only woth channel entries. So you should have a separate entry corresponding to each image in order to use it.

  9. Wes McWhorter
    Wes McWhorter 28 Jul 2011

    I’m desperately trying to get a dynamic category value into this plug-in and it’s giving me a helluva time. Broke down and even wrote a little PHP code to try and get it sorted. I’m using the Entry Categories plug-in to get the Category name, then trying to pass it into the Entry Linking plugin. I have channel entries that are grouped by category, and rather than use the EE next/previous tags, I bought this one because I thought I could filter by category. It totally works if I hard code in the category value - “Residential” for example - but when I try this dynamically, this thing just dies. Can you let me know what you think is going on? Code below. (hopefully it’ll show up)

    <?php
    $myCat = “{exp:entry_cats entry_id='{entry_id}’}{level0_category0_cat_name}{/exp:entry_cats}”;
    echo $myCat;
    ?>

    {exp:entry_linking entry_id="{entry_id}” link=“next” channel=“architecture” sort=“ASC” category=”<?php echo $myCat; ?>” status=“open” mode=“full” no_results=“empty”}< a class=“next” href=”{path=architecture/{link_url_title}}”>< img alt=“Next Project” src=”../images/ui/spacer.png” >< /a>{/exp:entry_linking}

    • Yuri Salimovskiy's avatar
      Yuri Salimovskiy 28 Jul 2011

      Wes, the way you’re doing it will never work. PHP can be processed either on input or output stage, and you’re trying to use in on input of one tag but having data on output of another tag.
      Did you try

      {exp:entry_linking  category=”{exp:entry_cats entry_id=’{entry_id}’}{level0_category0_cat_name}{/exp:entry_cats}”} 

      ?
      If that does not work, you should use embedded templates.
      In your ‘main’ templates you’ll have

      {exp:entry_linking entry_id=”{entry_id}” link=“next” channel=“architecture” sort=“ASC” category=”{embed='_embeds/category' entry_id=’{entry_id}’}” status=“open” mode=“full” no_results=“empty”} 

      and in _embeds/category

      {exp:entry_cats entry_id=’{embed:entry_id}’}{level0_category0_cat_name}{/exp:entry_cats} 
      • Wes McWhorter
        Wes McWhorter 28 Jul 2011

        Yuri,
        Thanks for your help, man. I kinda figured that with regards to the PHP method. So, I tried both of the methods you recommended above, but they both give me a version of this error currently:

        Error Number: 1064
        You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘architecture/_cat_links’ entry_id=‘68’}’ ) AND ( t.status=‘open’ ) ORDER BY ent’ at line 1
        SELECT DISTINCT t.entry_id FROM exp_channel_titles AS t LEFT JOIN exp_channels AS w0 ON w0.channel_id=t.channel_id LEFT JOIN exp_category_posts AS cp0 ON cp0.entry_id=t.entry_id LEFT JOIN exp_categories AS c0 ON c0.cat_id=cp0.cat_id WHERE t.site_id=‘1’ AND ( w0.channel_name=‘architecture’ ) AND ( c0.cat_url_title=’{embed='architecture/_cat_links' entry_id='68'}’ ) AND ( t.status=‘open’ ) ORDER BY entry_date ASC
        Filename: third_party/entry_linking/pi.entry_linking.php
        Line Number: 158

        It almost seems like that value - {embed='architecture/_cat_links' entry_id='68'} - is getting passed directly into the SQL query, which obviously would never work.

        UPDATE: So, I modified the tags a bit to read like this:

        _entry.html template
        {exp:entry_linking entry_id="{entry_id}” link=“next” channel=“architecture” sort=“ASC” category=’{embed="architecture/_cat_links" entry_id="{entry_id}”}’ status=“open” mode=“full” no_results=“empty”}LINK GOES HERE{/exp:entry_linking}
        (NOTE: JUST SINGLE QUOTES AROUND THE CATEGORY PARAMETER)

        _cat_links.html template
        {exp:entry_cats entry_id="{embed:entry_id}”}{level0_category0_cat_name}{/exp:entry_cats}

        I did verify that the category name value is getting selected appropriately, but it’s still not working.

        The page loads correctly (no SQL errors), but my previous / next links don’t show.
        http://www.volpatohatz.com/architecture/residential-refurbishment-longueville-australia

        Bizarre. I’ll keep troubleshooting, but any thoughts would be appreciated.

        • Yuri Salimovskiy's avatar
          Yuri Salimovskiy 28 Jul 2011

          Hm, I wonder why the embed is not processed. Has something to do with parsing order, probably.
          Did you try nesting tags vice versa, i.e.

          {exp:entry_cats entry_id=’{entry_id}’}
          {exp
          :entry_linking entry_id=”{entry_id}” link=“next” channel=“architecture” sort=“ASC” category=”{level0_category0_cat_name}” status=“open” mode=“full” no_results=“empty”}class=“next” href=”{path=architecture/{link_url_title}}”>< img alt=“Next Project” src=../images/ui/spacer.png” >< /a>{/exp:entry_linking}
          {
          /exp:entry_cats} 
          • Wes McWhorter
            Wes McWhorter 28 Jul 2011

            Tried that:
            {exp:entry_cats entry_id="{entry_id}”}
            {exp:entry_linking entry_id="{entry_id}” link=“next” channel=“architecture” sort=“ASC” category=”{level0_category0_cat_name}” status=“open” mode=“full” no_results=“empty”}
            Next Project
            {/exp:entry_linking}
            {/exp:entry_cats}

            Page loads, but still no links.
            http://www.volpatohatz.com/architecture/residential-and-commercial-development-neutral-bay-australia

            • Yuri Salimovskiy's avatar
              Yuri Salimovskiy 28 Jul 2011

              And you say it works if category is hardcoded? You may try {level0_category0_cat_url_title} (the docs are mentioning name, but that’s wrong - url title is used)
              Other than this, I’m afraid there’s nothing I can help you. The only suggestion is to play with embeds (and make sure all received data are correct, i.e. work hardcoded)

  10. Wes McWhorter
    Wes McWhorter 28 Jul 2011

    Yuri!
    I got it, man. Adding this here, because I think it might benefit folks down the road.

    TEMPLATE: _entry.html (PHP set to parse on Output)
    <?php
    $myCat = “{exp:entry_cats entry_id='{entry_id}’}{level0_category0_cat_name}{/exp:entry_cats}”;
    ?>
    {embed="architecture/_cat_links" entry_id="{entry_id}” entry_cat=”<?php echo $myCat; ?>”}

    TEMPLATE: _cat_links.html

    {exp:entry_linking entry_id="{embed:entry_id}” link=“next” channel=“architecture” sort=“ASC” category=”{embed:entry_cat}” status=“open” mode=“full” no_results=“empty”}
    Next Project
    {/exp:entry_linking}
    {exp:entry_linking entry_id="{embed:entry_id}” link=“prev” channel=“architecture” sort=“ASC” category=”{embed:entry_cat}” status=“open” mode=“full” no_results=“empty”}

    {/exp:entry_linking}


    VOILA!!! Working like a charm.
    http://www.volpatohatz.com/architecture/residential-refurbishment-longueville-australia

    • Yuri Salimovskiy's avatar
      Yuri Salimovskiy 28 Jul 2011

      woohoo! glad you’ve got it working - and thanks for sharing the solution

  11. Wes McWhorter
    Wes McWhorter 30 Jul 2011

    Hey Yuri,
    I’m back again. Can you suggest a reason why this isn’t working as expected?
    http://www.volpatohatz.com/architecture/category
    It seems the only category grouping that causes the next/previous links to fire is the “Residential” section.
    Any insight is greatly appreciated. Thanks!
    ~
    Wes

    • Yuri Salimovskiy's avatar
      Yuri Salimovskiy 30 Jul 2011

      Emailed you.

About

    Hello, my name is Yuri and I specialize in creating custom add-ons (plugins, modules, extensions) for ExpressionEngine CMS.
    You can reach me anytime by emailing .(JavaScript must be enabled to view this email address)