Sunday, January 17th, 2010 (updated 11 Jun ’10)

Documentation for Nearby Entries v1.4.2

Username

Password

Forgot your password?

Register

Elsewhere...

Another excellent piece by Andy Rutledge, an admonition/checklist for being a professional designer/developer.

Both the BBC and Fox news web sites have recently been redesigned, with the BBC losing its looks and Fox getting neat and serious.

jQuery diagramming with jsPlumb — cool.

Another wonderful blog post by Walter Russell Mead, this time hoping that the blogosphere find a not-so-distant mirror in 18th-century London.

Google argues that its mobile YouTube site is better than its YouTube iPhone app.

Jakob Nielsen tests reading usability on the iPad and Kindle and reports that they’re almost as good as reading on paper. People didn’t like reading on PCs — it reminded them of work.

Falling out of love with the iPad. None of this surprises me.

Wow, icons made entirely in CSS3 (currently Safari, Chrome only).

Short film created entirely on the iPhone 4.

A day in the early life of an iPhone 4.

With the Nearby Entries plugin, you can display not only one but any number of next and previous entries. You can order next/previous links not only by entry date but by edit or expiration date or by title alphabetically.

You can also display custom fields from next/previous entries. And you can filter next/previous entries using standard weblog:entries parameters such as status, category, author and custom fields.

Getting slightly more complex, you can also select next/previous entries using one sort, then display them using a different sort, such as displaying the chronologically next 10 entries alphabetically by title.

Compatibility

Works with both EE v1 and v2.

Installation

EE v1.x

Place the pi.nearby_entries.php file in the /system/plugins folder.

EE v2.x

Create a folder /nearby_entries within the /third_party folder. Place the pi.nearby_entries.php file in there.

Tags

The plugin has two tags, both used the same way: exp:nearby_entries:next and exp:nearby_entries:prev.

Parameters

Required parameters

this_entryid

This is the entry from which the previous and next entries are determined. Required unless both the this_urltitle and this_weblog parameters are entered instead.

this_urltitle

This is the entry from which the previous and next entries are determined. Requires completing the this_weblog parameter as well.

this_weblog / this_channel

Helps determine the entry from which the previous and next entries are determined. Required if determining the entry using the this_urltitle parameter. Use this_weblog for EE v1, this_channel for EE v2.

site

Required if using the Multiple Site Manager.

Optional parameters

allow_php

Defaults to “no”. If set to “y”, “Y”, “Yes” or “yes”, then EE’s native security measure of the values, xss_cleaning, is switched off, allowing PHP code within the plugin.

author_id

Works as in the weblog:entries tag.

category

Works as in the weblog:entries tag.

category_group

Works as in the weblog:entries tag.

day

Works as in the weblog:entries tag.

debug

Allowed values are Yes, yes, y or No, no, n. If set to yes, then no results are displayed; instead, a series of notes about the deployment of the plugin appear within a div of class “nearby-entries-message”. These notes should help debug usage of the plugin if the results aren’t as expected.

fixed_order

Works as in the weblog:entries tag.

group_id

Works as in the weblog:entries tag.

limit

Works as in the weblog:entries tag.

month

Works as in the weblog:entries tag.

offset

Works as in the weblog:entries tag.

orderby

Sets the sort order of the results, whereas the this_orderby parameter helps determine the content of the results. The only allowed values are all the columns in the exp_weblog_titles table, among them entry_date (default), edit_date, expiration_date, recent_comment_date and title.

parse

Setting parse=“inward” allows another plugin to be placed within External Entries. (This is a universal parameter that works in all plugins.)

search:[field_name]

Works as in the weblog:entries tag.

show_expired

Works as in the weblog:entries tag.

show_future_entries

Works as in the weblog:entries tag.

sort

Sets the sort order of the results, whereas the this_sort parameter helps determine the content of the results.

status

Works as in the weblog:entries tag.

sticky

Works as in the weblog:entries tag.

start_on

Works as in the weblog:entries tag.

stop_before

Works as in the weblog:entries tag.

this_orderby

With this_orderby you can set the entry order from which your set of next and previous entries will be selected. For example, you may want to display the previous 10 entries from the current one, but display them alphabetically by title rather than chronologically. In this scenario you’d set this_orderby as “entry_date” (in this case its default value) then orderby as “title”.

this_sort

The this_sort parameter complements the this_orderby one. The default value is “desc”.

year

Works as in the weblog:entries tag.

Variables

{nearby:count}

Works as in the weblog:entries tag.

{nearby:total_results}

Works as in the weblog:entries tag.

{nearby:[field_name]}

Text input and text area custom fields can be displayed.

Relationship fields cannot be displayed (though try the Tied Entries plugin for that!).

Date variables cannot be displayed the regular way, ie, {tied:entry_date format=”%D/%M/%Y”}. Instead, use PHP (set the PHP parsing stage to “output”):

<?php echo date("D/F/Y""{tied:entry_date}"); ?> 

Note that PHP’s date format codes are slightly different to EE’s own. They’re posted at PHP’s date function manual page.

Examples

For a site using the blog-standard /year/month/date/url_title format for URLs, for which ExpressionEngine is not designed, the standard next/previous tags simply don’t work. So we need to use the Nearby Entries plugin instead:

<div class="nextprev nextprev-single">
    <
div class="nav-previous">
        <
span class="nextprev-arrow">&lsaquo;</span>
        
{exp:nearby_entries:prev this_urltitle="{segment_4}" this_weblog="blog" debug="n" limit="1"}
        
<a href="{path=/}<?php echo date("Y/m/d", "{nearby:entry_date}"); ?>/{nearby:url_title}">
            <
span class="nextprev-post">Previous Post</span>
            <
span class="nextprev-single-link-title">{nearby:title}</span>
        </
a>
        
{/exp:nearby_entries:prev}
    
</div><!-- /.nav-previous -->
    <
div class="nav-next">
        
{exp:nearby_entries:next this_urltitle="{segment_4}" this_weblog="blog" debug="n" limit="1"}
        
<a href="{path=/}<?php echo date("Y/m/d", "{nearby:entry_date}"); ?>/{nearby:url_title}">
            <
span class="nextprev-post">Next Post</span>
            <
span class="nextprev-single-link-title">{nearby:title}</span>
        </
a>
        
{/exp:nearby_entries:next}
        
<span class="nextprev-arrow">&rsaquo;</span>
    </
div><!-- /.nav-next -->
</
div><!-- /.nextprev --> 

Note that date fields cannot be output in the usual way, but instead need some assistance from PHP (be sure to switch on PHP for the template).

Changelog

v.1.4.2 (2010 June 11)

  • fixed issue raised by Kyle Batson where using the author_id parameter caused PHP notices in some situations

v.1.4 (2010 May 7)

  • changed syntax, now using EE’s db library, adapting to changes in EEv2.0.2

v.1.3.1 (2010 Apr 12)

  • added allow_php parameter to override variable cleaning and allow PHP (thanks to Michael G Rose)

v.1.3 (2010 Apr 9)

  • added security measures: SQL Injection Prevention for parameters, Variable Cleaning for values

v.1.2.4 (2010 Apr 6)

  • fixed bug introduced in v1.2.3 where next and prev were reversed

v.1.2.3 (2010 Apr 5)

  • fixed bug where sorting produced unpredictable results
  • added this_orderby and this_sort parameters

v.1.1.3 (2010 Mar 1)

  • fixed bug where variables weren’t resetting for checking version when plugin called more than once on a template

v.1.1.2 (2010 Mar 1)

  • fixed bug where using parameters this_weblog and this_urltitle instead of this_entryid wasn’t working in EEv2.x

v.1.1.1 (2010 Feb 23)

  • fixed bug where using parameters this_weblog and this_urltitle instead of this_entryid wasn’t working in EEv1.x

v.1.1 (2010 Feb 13)

  • now works for both EE v1 and v2

v.1.0.4 (2010 Jan 29)

  • declared the $output variable so that no PHP messages are sent if it never gets defined

v.1.0.3 (2010 Jan 18)

  • added author_id parameter

v.1.0.2 (2010 Jan 17)

  • added offset, group_id, sticky, fixed_order parameters

v.1.0.1 (2010 Jan 17)

  • added category and category_group parameters

Roadmap

  • add multiple weblog support, ie, piping in the this_weblog parameter
  • change this_weblog parameter to this_channel for EE v2

Mon 18 Jan ’10
4:11pm

Terry Evans

This extension loolks really great.

Say I have a weblog and I want to show the next previous entries of only the currently viewed weblog entry’s author.  Is it possible to filter entries by author?

Mon 18 Jan ’10
4:15pm

Adam Khan

Yes, there’s an author_id parameter, documenting it now.

Mon 18 Jan ’10
4:39pm

Terry Evans

Awesome. This solves a major hurdle for me. Sending $$ to you today.

Mon 18 Jan ’10
4:53pm

Adam Khan

Excellent, post here if any problems. Remember the debug=“y” parameter can be helpful if you’re not getting the results you expect.

Mon 18 Jan ’10
5:51pm

Adam Khan

My mistake, the reason the author_id parameter wasn’t documented is because it wasn’t there. Now added in v1.0.3.

Thu 21 Jan ’10
2:53am

Steve Hurst

It figures, I just solved this issue with custom query tags… where were you a month ago? :)

Fri 29 Jan ’10
9:45am

shine

Hi Adam,

Using the above example returns:

Notice: Undefined variable: output in /home/club/public_html/admin/plugins/pi.nearby_entries.php on line 364

Notice: Undefined variable: output in /home/club/public_html/admin/plugins/pi.nearby_entries.php on line 364

I have enabled php for the template. I am basically trying to use the plugin to mimic something textpattern or wordpress does out of the box whereby you can link to next and previous entries in the same weblog.

e.g. http://www.opensourcecms.com/demo/1/85/Textpattern demo showing linking to next and previous at the bottom.

Any help would be great. Cheers!

Shine

Fri 29 Jan ’10
3:01pm

Adam Khan

Shine,

I’ve updated to v1.0.4 so that there won’t be a PHP notice from if the $output variable never gets defined.

A couple of things: are you sure you even need this plugin? If you just need a simple single next and previous from the same weblog, EE’s own built-in next and previous tags should be fine.

If you’re not getting any output at all, try the debug=“yes” parameter and see what it tells you.

Fri 29 Jan ’10
3:40pm

shine

Adam thanks for you quick response and fix.

I have looked at the built-in ee next and previous tags over at http://expressionengine.com/docs/modules/weblog/entry_linking.html

I was unaware I could do what I wanted with the built-in tags because I was not getting any output.

For example I have a weblog called spring collection. I then have for example 10 entries called tops, jeans, shoes etc etc.

I simply want the user to land on the page and view the latest entry and then have a button to have a link to the next and previous entries within the same weblog.

I assumed that your plugin was necessary to get this working.

Just will have to play about with both options to see if I can execute what I want.

Thanks once again.

Shine

Tue 23 Feb ’10
8:01pm

Tyler

I have just set the this_weblog (text) and this_urltitle (segment var) but still get no output. I have set debug to “yes” and I get this

Method: prev

This entry ID:

Prelim query:

Raw results: Array

Fields SQL:

Nearby Entries errors:

If there’s no entry_id there must be both a url_title and a weblog_name.

It looks like its not pulling the url_title / weblog to determine which entry it should be. Please help. Thanks!

Tue 23 Feb ’10
11:33pm

Adam Khan

Tyler, you’re right, it’s a bug introduced with v1.1, making the plugin compatible with both EE v1 and v2. Try the new version, v1.1.1, that should address the problem. (Good to see the debug option in use!)

Tue 23 Feb ’10
11:43pm

Tyler

Now were talking! Does exactly what I want. Brilliant plug-in!

Tue 23 Feb ’10
11:50pm

Adam Khan

Thanks, Tyler, pleased to hear it.

Tue 23 Feb ’10
11:58pm

Tyler

Using it with Low Seg2Cat to completely free up the URL structure in EE.

Wed 24 Feb ’10
9:37am

Adam Khan

> Using it with Low Seg2Cat to completely free up the URL structure in EE.

Crazy sh*t. Would be interesting to see an article on this.

Sun 28 Feb ’10
11:55pm

trif3cta

Fantastic plugin idea, although I’m having the same issue that Tyler was. I’m using 1.1.1.

I’m providing this_urltitle=’{segment_x}’ and this_weblog=‘channel_name’ in debug mode and getting back:

If there’s no entry_id there must be both a url_title and a weblog_name.

Thanks for the help.

@Tyler - pls do share, that sounds wicked.

Mon 1 Mar ’10
9:22am

Adam Khan

trif3cta, are you using Multiple Site Manager?

Mon 1 Mar ’10
3:16pm

trif3cta

Nope. My setup is like so:

/staff/profile/name

Name (segment 3) is what I want to key off, and I have a channel called staff.  So this_urltitle=”{segment_3}” this_weblog=“staff” gives me the error.

The entry ID method returns the right data, however it’s not what I need in this particular case.

Thanks so much for the help.

Mon 1 Mar ’10
5:59pm

Adam Khan

trif3cta, it wasn’t working in EEv2. Try downloading v1.1.2.

Mon 1 Mar ’10
7:59pm

trif3cta

Thanks Adam, that seemed to fix it. 

For some reason I can’t run both functions in the same template, whichever one listed first outputs the results of the query and the other one is blank (or in debug mode, it gives the (If there’s no entry….).

Forgive me if I’m being dense.

Mon 1 Mar ’10
8:58pm

Adam Khan

trif3cta, the density is all mine. Fixed in v1.1.3…

Tue 2 Mar ’10
2:42am

trif3cta

Works like a charm. Gracias.

Thu 1 Apr ’10
6:03am

vinay

I am not able to sort the entries in

{exp:nearby_entries:next this_urltitle=”{segment_3}” this_weblog=“photos” debug=“n” limit=“5” orderby=“entry_id” sort=“desc”}

The output entries always gets sorted in “ASC” rather than what i specified. Anyway to solve this?

Thu 1 Apr ’10
6:06am

vinay

Actually when i use sort=“asc” in next loop, i get very weird results… very random entries…

Thu 1 Apr ’10
10:23am

Adam Khan

Thanks for trying the plugin, vinay. I’m taking a look now at the problem…

Thu 1 Apr ’10
11:09am

Adam Khan

Vinay, I’m seeing that when using orderby=“entry_id” and sort=“asc” for the next function, it ends up producing the same thing as the previous function. Working on it.

Thu 1 Apr ’10
4:39pm

Adam Khan

Vinya, there was a step missing in the logic, which I’m trying to fix, but the plugin won’t take two instances of a weblog (well, it does, but the second one ignores important parameters).

I’ve got to give up on this today—I’ll resume working on the fix tomorrow or Sunday.

Mon 5 Apr ’10
5:20am

vinay

Hi Adam,

Thanks for the info. Let me know if you fix this.

Mon 5 Apr ’10
11:41am

Adam Khan

Vinay, you can now download v1.2.3, and the problem should be fixed.

Because the fix required another level of complexity, the plugin now also has another level of control. See the this_orderby and this_sort parameters.

Tue 6 Apr ’10
1:49am

vikhel

Hi Adam, I am trying to download v1.2.3, but there is an error that says

“Oops, there is no file at this URL. Hopefully you can find what you’re looking for in the adjacent lists.”

Tue 6 Apr ’10
2:12am

Adam Khan

Vikhel, thanks for the heads-up. Try now.

Tue 6 Apr ’10
2:41am

vikhel

Hi Adam,

Getting this error when there are no prev entries

Notice: Trying to get property of non-object in /data/home/app/www/system/plugins/pi.nearby_entries.php on line 100

Warning: Invalid argument supplied for foreach() in /data/home/app/www/system/plugins/pi.nearby_entries.php on line 108

Tue 6 Apr ’10
2:46am

Adam Khan

Will fix that tomorrow (late here, need to be fully awake…).

Tue 6 Apr ’10
9:42am

Adam Khan

Vikhel, I can’t replicate this problem. Can you switch the debug paramter to “yes” and either post the results here or email me them?

Meanwhile I’ve updated the plugin to v1.2.4.

Wed 7 Apr ’10
2:43am

vikhel

Hi Adam,

I am using next loop inside weblog:entries

{exp:weblog:entries weblog=“contest_photos” limit=“1” disable=“trackbacks|comments” status=“Open|Featured”}
              {exp:nearby_entries:next this_entryid=”{entry_id}” debug=“n” limit=“5”}
                {embed=“seaawards/photocarousel” curEntryID=”{nearby:entry_id}”}
              {/exp:nearby_entries:next}
              {/exp:weblog:entries}

The error appears only when you are viewing the latest entry. As there is no next entries, it displays the error. When i set debug=“y”, i get

Notice: Undefined variable: fields_sql in /data/home/app/www/system/plugins/pi.nearby_entries.php on line 642

Notice: Undefined variable: final_sql in /data/home/app/www/system/plugins/pi.nearby_entries.php on line 643

Wed 7 Apr ’10
6:33pm

Adam Khan

Vikhel, those are errors generated by EE. The plugin itself should generate some info instead of the actual output when its debug paramter is set to “y”.

I tried on the latest entry myself and didn’t get those errors, that’s why I’m thinking maybe there’s a clue in the plugin’s own debug notes in your scenario.

Sat 10 Apr ’10
10:21pm

mgr88

Hi Adam,

I’m just trying it out and using the code snippet for year/month/date links, with appropriate changes for EE2. It all works well except that the php code doesn’t parse when it is inside the nearby tags.

I’ve got php enabled for the template and when I put the equivalent php date code outside the tags it gives the date with correct formatting. But when the code is inside the tags the output is a literal repeat of the code.

Michael

p.s. thanks for the great “How I Built Subtraction” article.

Sun 11 Apr ’10
9:49am

Adam Khan

Michael,

Thanks for trying the plugin. Did you try the parse=“inward” parameter?

Sun 11 Apr ’10
10:53am

mgr88

Hi Adam, I just added the parse=“inward’ parameter. It hasn’t made a difference. I’m using EE 2.0.1 on MAMP 1.8.4 and MasOSX 10.6.3.
This segment of input with the same 2 calls, one inside and one outside:
                          {exp:nearby_entries:next ......
                                            ....
                <?php echo date(“Y/m/d”, “{entry_date}”); ?>
                {/exp:nearby_entries:next}
                          <?php echo date(“Y/m/d”, “{entry_date}”); ?>
Gives this output
                    <?php echo date(“Y/m/d”, “1213886097”); ?>
                    2008/06/19

Michael

Sun 11 Apr ’10
5:40pm

Adam Khan

Michael, one other thing—is PHP set to the output rather than input stage in template settings? It won’t work with PHP set as input—no plugin will I don’t think, due to EE’s template parsing order.

Sun 11 Apr ’10
7:30pm

mgr88

Hi Adam, yes, PHP is set to output.
As a check to see if it was a general issue with plugins, I put the same php code inside twitter timeline tags on the same page. That rendered the dates correctly.

I also checked the logs inside MAMP and couldn’t find any error messages.
Michael

Mon 12 Apr ’10
7:39am

Adam Khan

Michael, the problem was due to introducing EE’s xss_cleaning functionality in v1.3.

I’ve added a parameter to v1.3.1 of the plugin, allow_php, which if set to “yes”, makes the plugin not use xss_cleaning, thereby allowing PHP within the plugin.

Thanks for the heads up, I’ll add this parameter to other plugins.

Mon 12 Apr ’10
10:33am

mgr88

That fixed it. Thanks so much for your prompt help.

Michael

Mon 26 Apr ’10
5:13pm

mgr88

Hi Adam, sorry to bother you again. I just upgraded EE to version 2.0.2 and something seems to have changed. The plugin now gives the following error.
Cheers,
Michael

A PHP Error was encountered
Severity: Notice
Message: Undefined property: Channel::$query
Filename: nearby_entries/pi.nearby_entries.php
Line Number: 586

Wed 28 Apr ’10
2:28pm

Adam Khan

Sorry about the delay Michael, I’ve been travelling this last day. Will get to the fix as soon as I can.

Wed 5 May ’10
7:11am

Adam Khan

Michael, I had to take an unscheduled trip and am now back and catching up. My apologies again for letting this problem sit so long. I’ll be addressing it today, Wednesday.

Fri 7 May ’10
6:30am

Adam Khan

Michael, change made to adapt to changes in EEv2.0.2. Should work now.

Tue 11 May ’10
9:05am

mgr88

Hi Adam,

thanks again for this.

Fri 21 May ’10
4:37pm

Kyle Batson

Hi Adam,
The plugin is working properly except for getting to an entry that has no previous entry. When that happens it outputs the following error:

Notice: Trying to get property of non-object in /plugins/pi.nearby_entries.php on line 103

Warning: Invalid argument supplied for foreach() in /plugins/pi.nearby_entries.php on line 111

This is my code:
{exp:weblog:entries weblog=“comics” limit=“1”}
{comic_image}
{exp:nearby_entries:prev this_entryid=”{entry_id}” this_weblog=“comics” author_id=”{author_id}” limit=“1”}{nearby:entry_id}{/exp:nearby_entries:prev}
{/exp:weblog:entries}

Fri 21 May ’10
5:43pm

Adam Khan

Kyle, I’m not able to replicate that problem. Can you plugin in the debug=“y” parameter and report the results here? You’re on EE v1.x, right?

Fri 21 May ’10
8:08pm

Kyle Batson

Turning on debug added the following errors:
Notice: Undefined variable: fields_sql in /plugins/pi.nearby_entries.php on line 650

Notice: Undefined variable: final_sql in /plugins/pi.nearby_entries.php on line 651

Parse error: syntax error, unexpected T_LNUMBER in /core/core.functions.php(653) : eval()‘d code on line 5

Method: prev

This entry ID: 2

Prelim SQL: SELECT entry_id FROM exp_weblog_titles WHERE weblog_id = ‘1’ ORDER BY entry_date desc

Raw results: 1

Limited results:

Fields SQL:

Final SQL:

Fri 21 May ’10
8:09pm

Kyle Batson

And yes. EE 1.6.9, latest build.

Tue 8 Jun ’10
8:06pm

Kyle Batson

Any thoughts Adam? Thanks.

Thu 10 Jun ’10
6:43am

Adam Khan

Sorry Kyle, I forgot all about this one. Will get on it this afternoon (UK time) and try again to discover the problem.

Thu 10 Jun ’10
8:08pm

Kyle Batson

No worries.
Let me know if there’s anything I can do to help.

Fri 11 Jun ’10
8:07am

Adam Khan

Kyle, how many entries do you have in the Comics weblog?

Fri 11 Jun ’10
9:17pm

Adam Khan

Thanks for staying on this, Kyle. Problem now fixed in v1.4.2.

Post a comment

Name:

Email:

Location:

URL:

Your comment:

Remember my personal information
Notify me of follow-up comments?

Please enter the word you see in the image below:

What is the sum of 3 and 8? (2 character(s) required)