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}"}<p><a href="{path=my_template_group/my_template}">Previous</a></p>{/exp:weblog:prev_entry}
{exp:weblog:next_entry category="5" entry_id="{entry_id_number}"}<p><a href="{path=my_template_group/my_template}">Next</a></p>{/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’.
Place this tag in any of your templates.
Changelog:
- 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.
