We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Plugin: Entry Id

Development and Programming

Laisvunas's avatar
Laisvunas
879 posts
17 years ago
Laisvunas's avatar Laisvunas

The attached add-on files may be out of date. Please visit Devot-ee for the latest versions.

Hi,

I would like to present to your attention a new plugin: Entry Id.

It allows to find entry id of the entry or entry ids of several entries which have characteristics specified in parameters of the {exp:entry_id} tag.

PARAMETERS:

1) weblog - Optional. Allows you to specify weblog name.

2) category - Optional. Allows you to specify category id number (the id number of each category is displayed in the Control Panel).

3) url_title - Optional. Allows you to specify URL title of the entry.

At least one out of “weblog”, “category” and “url_title” parameters must be defined.

4) allow_multiple_results - Optional. Allows you to specify if you want to display entry id numbers of multiple entries (value ‘yes’) or just of one entry (value ‘no’). Default is ‘no’. ‘limit’, ‘sort’ and ‘sort_by’ parameters are used in cases when the value of this parameter is ‘yes’.

5) limit - Optional. Allows you to specify number of entries to be displayed. Default value is ‘10’. Set it to ‘none’ if you want to display all entries found.

6) sort - Optional. Allows you to specify how entries found should be sorted - ascending (value ‘asc’) or descending (value ‘desc’). Default is ‘asc’.

7) sort_by - Optional. Allows you to specify by what criterion entries found should be sorted - by date (value ‘date’) or by title (value ‘title’). Default is ‘date’.

8) on_failure - (any string which consists from characters legal for use in ExpressionEngine’s tag parameter values). Optional. Allows you to specify what {exp:entry_id} tag will output in case an entry which belongs to weblog and/or is posted into category having id number and/or has url_title as specified in parameters does not exist.

9) invalid_input - Optional. Accepts two values: “alert” and “silence”. Default value is “silence”. If the value is “alert”, then in cases when some parameter’s value is invalid plugin exits and PHP alert is being shown; if the value is “silence”, then in cases when some parameter’s value is invalid plugin finishes its work without any alert being shown. Set this parameter to “alert” for development, and to “silence” - for deployment.

EXAMPLE OF USAGE:

If your weblog name is “my_weblog”, your category id number is “5”, and url_title of your entry is “my_entry”,
then the variable {entry_id_number} within {exp:entry_id}{/exp:entry_id} tag pair

{exp:entry_id weblog="my_weblog" category="5" url_title="my_entry"}
{entry_id_number}
{/exp:entry_id}

will return entry id of the entry.

You can use variable’s {entry_id_number} output as parameter of other tag. For such use you must add parse=”inward” parameter to {exp:entry_id} tag.

For example, code as this will work

{exp:entry_id weblog="my_weblog" url_title="my_entry" parse="inward"}
{exp:weblog:prev_entry category="5" entry_id="{entry_id_number}"}<a href="http://{path=my_template_group/my_template}">Previous</a>{/exp:weblog:prev_entry}
{exp:weblog:next_entry category="5" entry_id="{entry_id_number}"}<a href="http://{path=my_template_group/my_template}">Next</a>{/exp:weblog:next_entry}
{/exp:entry_id_id}

If entry which belongs to weblog and/or is posted into category having id number and/or has url_title as specified in parameters does not exist, then {entry_id_number} variable by default will return nothing. In case ‘on_failure’ parameter was defined, then, in such case the {entry_id_number} variable will output what was specified as a value of this parameter. Also {entry_id_number} variable will return the value of ‘on_failure’ parameter in case when more than one entry was found and ‘allow_multiple_results’ parameter has the value ‘no’.

Conditionals are supported.

Entry Id2 is clone of Entry Id. Having installed both Entry Id and Entry Id2 you can write the code as this:

{exp:entry_id category="5" weblog="my_weblog" sort="asc" limit="1"}
{if entry_id_number!=""}
Some code
{if:else}
{exp:entry_id2 category="8" weblog="my_other_weblog" sort="asc" limit="1"}
{if entry_id_number2!=""}
Some code
{/if}
{/exp:entry_id2}
{/if}
{/exp:entry_id}

Changelog:

  • 1.3 // Added support for conditionals.
  • 1.2.1 // Bug fixed - simple validation of parameters values being too restrictive.
  • 1.2 // Ditched support for single tag. Added parameters “allow_multiple_results”, “limit”, “sort” and “sort_by”.
  • 1.1.1 // Bug fixed - output of exp:entry_id tag being different in case “weblog” or “category” or “url_title” parameter not defined and in case parameter’s value being empty string.
  • 1.1 // Added invalid_input parameter.
  • 1.0 // Initial release.
       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

Hi,

I have released a version 1.1 of Entry Id plugin.

In this release parameter “invalid_input” was added. This parameter accepts two values: “alert” and “silence”. Default value is “silence”. If the value is “alert”, then in cases when some parameter’s value is invalid plugin exits and PHP alert is being shown; if the value is “silence”, then in cases when some parameter’s value is invalid the plugin finishes its work without any alert being shown. Set this parameter to “alert” for development, and to “silence” - for deployment.

Since the plugin does not do comprehensive validation of parameters’ values, you cannot be absolutely sure that in cases no alert was thrown the input was really valid.

You may ask, why parameter “invalid_input” was needed there already “on_failure” parameter being available. The answer is, these parameters have different purposes. Using parameter “invalid_input” you can specify what plugin should do in case it considers some parameter’s value being invalid; using parameter “on_failure” you can specify what plugin should do in case it considers all parameters’ values being valid, but has found nothing to output.

       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

Hi,

I have released a version 1.1.1 of Entry Id plugin.

In this release a bug was fixed - output of exp:entry_id tag being different in case “weblog” or “category” or “url_title” parameter not defined and in case parameter’s value being empty string.

The bug can cause problems in cases parameters are supplied dynamically, especially when the number of dynamically supplied parameters can be different.

It is recommended to upgrade if you use the plugin in such situations.

       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

Hi,

I have released a version 1.2 of Entry Id plugin.

Two changes were introduced in this release:

1) Support for single tag was dropped. That is, from the version 1.2 on it will be no more possible to use single tag as here:

{exp:entry_id weblog="my_weblog" category="5" url_title="my_entry"}

Instead the variable {entry_id_number} within {exp:entry_id}{/exp:entry_id} tag pair should be used as here:

{exp:entry_id weblog="my_weblog" category="5" url_title="my_entry"}
{entry_id_number}
{/exp:entry_id}

For the justification of this step it can be said that support for single tags introduces minimal simplification of coding at the cost of significant complication of plugin’s code.

2) Added parameters “allow_multiple_results”, “limit”, “sort” and “sort_by”. “allow_multiple_results” allows you to specify if you want to display entry id numbers of multiple entries (value ‘yes’) or just of one entry (value ‘no’). Default is ‘no’. ‘limit’, ‘sort’ and ‘sort_by’ parameters are used when the value of “allow_multiple_results” parameter is ‘yes’ to specify how many and in which order entries should be displayed.

       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

Hi,

I have released a version 1.2.1 of Entry Id plugin.

In this release a minor bug was fixed - simple validation of parameters’ values being too restrictive in case when parameter’s value is supplied by embedded template variable.

       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

Hi,

I have released a version 1.3 of Entry Id plugin.

In this release support for conditionals was added.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.