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 - Weblog URL.
This plugin allows you to find weblog url as specified in weblog preferences.
VARIABLES:
1) weblog_url - outputs weblog url as specified in Control Panel.
2) weblog_short_name - outputs short name of the weblog.
PARAMETERS:
1) entry_id - Optional. Allows you to specify entry_id.
2) on_failure - (any string which consists from characters legal for use in ExpressionEngine’s tag parameter values). Optional. Allows you to specify what {exp:weblog_url} tag will output in case an entry having specified entry_id does not exist or the weblog to which entry was posted does not have weblog url specified in preferences.
If you leave entry_id parameter undefined, you must use {weblog_url:entry_id_start}{weblog_url:entry_id_end} variable pair.
EXAMPLE OF USAGE:
If entry_id is e.g. 246 then you can use optionally either single tag as here
{exp:weblog_url entry_id="246"}
or variable {weblog_url} within {exp:weblog_url}{/exp:weblog_url} tag pair as here
{exp:weblog_url entry_id="246"}
{weblog_url}
{/exp:weblog_url}
Both will return weblog url as specified in weblog preferences.
You will use {exp:weblog_url}{/exp:weblog_url} tag pair in case there is a need for parse=”inward” parameter.
You may also instead of specifying entry_id as parameter of {exp:weblog_url} to wrap it with {weblog_url:entry_id_start}{weblog_url:entry_id_end} variable pair. For example the code as this is possible:
{exp:weblog_url}
{exp:weblog:prev_entry entry_id="110" category="5"}
<a href="http://{weblog_url:entry_id_start}{entry_id}{weblog_url:entry_id_end}{url_title}">Previous page: {title}</a>
{/exp:weblog:prev_entry}
{/exp:weblog_url}
{exp:weblog_url}
{exp:weblog:next_entry entry_id="110" category="5"}
<a href="http://{weblog_url:entry_id_start}{entry_id}{weblog_url:entry_id_end}{url_title}">Next page: {title}</a>
{/exp:weblog:next_entry}
{/exp:weblog_url}
Conditionals are supported. You can write the code as this:
{exp:weblog_url entry_id="246"}
{if weblog_short_name=="my_weblog"}
{weblog_url}
{if:else}
{weblog_short_name}
{/if}
{/exp:weblog_url}
If entry having entry_id specified in parameters or specified using {weblog_url:entry_id_start}{weblog_url:entry_id_end} variable pair using does not exist, then {exp:weblog_url} tag by default will return nothing. In case ‘on_failure’ parameter was defined, then, in such case the tag will output what was specified as a value of this parameter.
Place this tag in any of your templates.
I have developed this plugin in order to be able to supply weblog url inside the output of {exp:weblog:prev_entry} and {exp:weblog:next_entry} tags. These tags does not allow to pull weblog url which is specified in weblog preferences. Instead you must use {path=template_group/template} variable. This is very constricting if previous/next entries belong to different weblogs and should be displayed using different templates.
Changelog:
A great plugin, I am using it in tandem with your Entry Id plugin, and they have gotten me out of a huge pickle, so thank you!
However, I would say that you may wish to check your code as I get the following error if I use conditionals only:-
Warning: strpos() [function.strpos]: Empty delimiter in /usr/home/*snip*/system/plugins/pi.weblog_url.php on line 108
You see, in my scenario I only want to evaluate the value of weblog_short_name rather than use it, e.g.
{exp:entry_id url_title="{segment_3}" parse="inward"}
{exp:weblog_url entry_id="{entry_id_number}"}
{if weblog_short_name=="myweblog"}
<?php if ($lang!="") {
echo("<s.c.r.i.p.t. language=\"javascript\">location.href=\"/{segment_1}/{segment_2}/{segment_3}/lang/default/\"</s.c.r.i.p.t.>");
}
?>
{if:elseif weblog_short_name=="myweblog_de"}
<?php if ($lang!="_de") {
echo("<s.c.r.i.p.t. language=\"javascript\">location.href=\"/{segment_1}/{segment_2}/{segment_3}/lang/_de/\"</s.c.r.i.p.t.>");
}
?>
{if:elseif weblog_short_name=="myweblog_it"}
<?php if ($lang!="_it") {
echo("<s.c.r.i.p.t. language=\"javascript\">location.href=\"/{segment_1}/{segment_2}/{segment_3}/lang/_it/\"</s.c.r.i.p.t.>");
}
?>
{/if}
{/exp:weblog_url}
{/exp:entry_id}
What I have done for now is include an extra if:elseif that will never apply with the {weblog_short_name} tag placed in it.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.