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: Weblog URL

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 - 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:

  • 1.1.1 // Bug fixed - PHP error being shown when neither variables weblog_url or weblog_short_name nor variable pair {weblog_url:entry_id_start}{weblog_url:entry_id_end} is used.
  • 1.1 // Added support for conditionals. Added {weblog_short_name} variable.
  • 1.0 // Initial release.
       
odspi's avatar
odspi
29 posts
16 years ago
odspi's avatar odspi

some of your files, including this, seem to be corrupt

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

Hi odspi,

Just downloaded the plugin and it seems to be OK. That is, after unzipping I can see all code from beginning <?php to the ending ?>.

Try to download it using another browser and write if anything goes wrong.

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

Hi,

I have released version 1.1 of Weblog URL plugin.

In this release support for conditionals was added.

Also a new variable - {weblog_short_name}, which outputs short name (not title) of the weblog was introduced.

       
baboonbrand's avatar
baboonbrand
14 posts
16 years ago
baboonbrand's avatar baboonbrand

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.

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

Hi baboonbrand,

You spotted a bug.

I fixed it, so grab the version 1.1.1 using the link above and let me know if something goes wrong.

Many thanks for reporting.

       
baboonbrand's avatar
baboonbrand
14 posts
16 years ago
baboonbrand's avatar baboonbrand

Sorry for the delay in getting back to this thread. Problem now solved, thanks for the prompt response and fix Laisvunas!!

       
NKT com's avatar
NKT com
124 posts
15 years ago
NKT com's avatar NKT com

Would it be possible to use the weblog id instead of article id to get the details?

e.g.

{exp:weblog_url id="246"}{weblog_short_name}{/exp:weblog_url}

Or better yet…

{exp:weblog_url:shortname id="246"}
       
Laisvunas's avatar
Laisvunas
879 posts
15 years ago
Laisvunas's avatar Laisvunas

Hi,

You can use exp://weblog:info tag.

       

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.