Page 1 of 1

Plugins for Homepage Only, Pt. 2

Posted: Fri Sep 17, 2010 7:58 pm
by tpelia
I am trying without success to add code for a plugin (with a "html nugget") that will allow that plugin to appear ONLY on the "home," or "index," page.

I don't want the plugin to appear on any of the "category" pages, nor on any of the "archives" pages, just ONE page.

So far, I have been able (through your gracious help!) to have the plugin NOT appear on any of the "category" pages with a "sidebar hider" plugin. But I have not been able to do this same for "archives" pages.

I'm sure there is a way to do this, but I am not adept enough to figure it out!

Does anyone have any suggestions?

Any help would be appreciated!!!

Re: Plugins for Homepage Only, Pt. 2

Posted: Sat Sep 18, 2010 1:28 am
by garvinhicking
Hi!

I suppose the easiest way is to edit your template's sidebar.tpl template file. Inside the loop where each plugin is emitted you could add a siwtch like:

Code: Select all

{foreach from=$plugindata item=item}
    {if $item.class == 'serendipity_plugin_myplugin' AND $view == 'archives'}
     <!-- plugin hidden! -->
    {else}
    <div class="serendipitySideBarItem container_{$item.class}">
        {if $item.title != ""}<h3 class="serendipitySideBarTitle {$item.class}"
        <div class="serendipitySideBarContent">{$item.content}</div>
    </div>
    {/if}
{/foreach}
HTH,
Garvin

Re: Plugins for Homepage Only, Pt. 2

Posted: Mon Nov 01, 2010 8:16 pm
by Maccsta
garvinhicking wrote:Hi!

I suppose the easiest way is to edit your template's sidebar.tpl template file. Inside the loop where each plugin is emitted you could add a siwtch like:

Code: Select all

{foreach from=$plugindata item=item}
    {if $item.class == 'serendipity_plugin_myplugin' AND $view == 'archives'}
     <!-- plugin hidden! -->
    {else}
    <div class="serendipitySideBarItem container_{$item.class}">
        {if $item.title != ""}<h3 class="serendipitySideBarTitle {$item.class}"
        <div class="serendipitySideBarContent">{$item.content}</div>
    </div>
    {/if}
{/foreach}
HTH,
Garvin
This code doesn't work for me. I added it to the sidebar plugin and get an error.

Code: Select all

Fatal error: Smarty error: [in file:/www.domain.com/blog/templates/default/sidebar.tpl line 11]: syntax error: mismatched tag {/foreach}. expected {/if} (opened line 5). (Smarty_Compiler.class.php, line 2338) in /www.domain.com/blog/bundled-libs/Smarty/libs/Smarty.class.php on line 1093

I just want to disable the serendipity_plugin_externalphp for all pages apart from the index page.

What am I doing wrong? Thanks for any help :)

Re: Plugins for Homepage Only, Pt. 2

Posted: Tue Nov 02, 2010 9:34 am
by garvinhicking
Hi!

My code wasn't properly meant to be copy and pasted; I was missing some characters in this line:

Code: Select all

{if $item.title != ""}<h3 class="serendipitySideBarTitle {$item.class}"
you would need to edit your original sidebar.tpl, and insert only the first {if} and {else} part of the pasted code, which is the relevant. Or append the line above with the true contents of your sidebar.tpl...

HTH,
Garvin

Re: Plugins for Homepage Only, Pt. 2

Posted: Tue Nov 02, 2010 5:20 pm
by Maccsta
Sorry Gavin I'm completely useless at this! So I edited the sidebar.tpl with this and all the sidebar plugins disappeared. How do I tweak it to just show the externalphp plugin on just the home page?

Code: Select all

{foreach from=$plugindata item=item}
    {if $item.class == 'serendipity_plugin_externalphp' AND $view == 'archives'}
     <!-- plugin hidden! -->
        <div class="serendipitySideBarItem container_{$item.class}">
        {$item.title != ""}<h3 class="serendipitySideBarTitle {$item.class}"
        <div class="serendipitySideBarContent">{$item.content}</div>
    </div>
    {/if}
{/foreach}

Re: Plugins for Homepage Only, Pt. 2

Posted: Wed Nov 03, 2010 9:34 am
by garvinhicking
Hi!

Try this:

Code: Select all

{foreach from=$plugindata item=item}
    {if $item.class == 'serendipity_plugin_externalphp' AND $view == 'archives'}
     <!-- plugin hidden! -->
    {else}
        <div class="serendipitySideBarItem container_{$item.class}">
        {$item.title != ""}<h3 class="serendipitySideBarTitle {$item.class}"
        <div class="serendipitySideBarContent">{$item.content}</div>
    </div>
    {/if}
{/foreach}
Only this "else" was missing! :)

HTH,
Garvin

Re: Plugins for Homepage Only, Pt. 2

Posted: Wed Nov 03, 2010 11:11 pm
by Maccsta
:( That doesn't work for me either, the sidebar now looks all funny and the externalphp plugin still shows on all pages, see here: http://www.jamesmcara.com/blog/

This is the exact code in my sidebar.tpl :

Code: Select all

{if $is_raw_mode}
<div id="serendipity{$pluginside}SideBar">
{/if}
{foreach from=$plugindata item=item}
    {if $item.class == 'serendipity_plugin_externalphp' AND $view == 'archives'}
     <!-- plugin hidden! -->
    {else}
        <div class="serendipitySideBarItem container_{$item.class}">
        {$item.title != ""}<h3 class="serendipitySideBarTitle {$item.class}"
        <div class="serendipitySideBarContent">{$item.content}</div>
    </div>
    {/if}
{/foreach}


{if $is_raw_mode}
</div>
{/if}

Re: Plugins for Homepage Only, Pt. 2

Posted: Thu Nov 04, 2010 9:59 am
by garvinhicking
Hi!

I'm sorry. I didn't notice the code you pasted still had the invalid code of my original template. I thought you looked it up in your template.

Now I did that work.

Code: Select all

{if $is_raw_mode}
<div id="serendipity{$pluginside}SideBar">
{/if}

{foreach from=$plugindata item=item}
    {if $item.class == 'serendipity_plugin_externalphp' AND $view == 'archives'}
     <!-- plugin hidden! -->
    {else}
    <div class="serendipitySideBarItem container_{$item.class}">
        {if $item.title != ""}<h3 class="serendipitySideBarTitle {$item.class}">{$item.title}</h3>{/if}
        <div class="serendipitySideBarContent">{$item.content}</div>
    </div>
    {/if}
{/foreach}

{if $is_raw_mode}
</div>
{/if}
Try to understand that and look up the original contents of your template to see what this actually does. :)

Regards,
Garvin

Re: Plugins for Homepage Only, Pt. 2

Posted: Thu Nov 04, 2010 10:01 pm
by Maccsta
Thanks Gavin, it seems to work now. The externalphp plugin now only shows on the index page. I added some extra parameters for the different views.

Was this the best way to do it? Have I missed anything out?

Code: Select all

{foreach from=$plugindata item=item}
    {if $item.class == 'serendipity_plugin_externalphp' AND $view == 'archives'}	  
	 {elseif $item.class == 'serendipity_plugin_externalphp' AND $view == 'archive'}
	 {elseif $item.class == 'serendipity_plugin_externalphp' AND $view == 'entry'}
	 {elseif $item.class == 'serendipity_plugin_externalphp' AND $view == 'categories'}
     {elseif $item.class == 'serendipity_plugin_externalphp' AND $view == 'staticpage'}
     <!-- plugin hidden! -->
    {else}
    <div class="serendipitySideBarItem container_{$item.class}">
        {if $item.title != ""}<h3 class="serendipitySideBarTitle {$item.class}">{$item.title}</h3>{/if}
        <div class="serendipitySideBarContent">{$item.content}</div>
    </div>
    {/if}
{/foreach}

Re: Plugins for Homepage Only, Pt. 2

Posted: Fri Nov 05, 2010 10:31 am
by garvinhicking
Hi!

That looks okay - I wouldn't immediately know of anything missing...

Regards,
Garvin

Re: Plugins for Homepage Only, Pt. 2

Posted: Fri Nov 05, 2010 5:44 pm
by Maccsta
Wouldn't this be a better use of the code using IF $view DOES NOT EQUAL ‘index’?

What is the view parameter for the index page?

Code: Select all

{foreach from=$plugindata item=item}
    {if $item.class == 'serendipity_plugin_externalphp' AND $view != 'index'}    
     <!-- plugin hidden! -->
    {else}
    <div class="serendipitySideBarItem container_{$item.class}">
        {if $item.title != ""}<h3 class="serendipitySideBarTitle {$item.class}">{$item.title}</h3>{/if}
        <div class="serendipitySideBarContent">{$item.content}</div>
    </div>
    {/if}
{/foreach}

Re: Plugins for Homepage Only, Pt. 2

Posted: Fri Nov 05, 2010 5:55 pm
by Maccsta
Ok I have nailed it this time! I was looking for 'start' :)

Can you just confirm there won't be any problems using that code Gavin?

Code: Select all

{foreach from=$plugindata item=item}
    {if $item.class == 'serendipity_plugin_externalphp' AND $view != 'start'}    
     <!-- plugin hidden! -->
    {else}
    <div class="serendipitySideBarItem container_{$item.class}">
        {if $item.title != ""}<h3 class="serendipitySideBarTitle {$item.class}">{$item.title}</h3>{/if}
        <div class="serendipitySideBarContent">{$item.content}</div>
    </div>
    {/if}
{/foreach}

Re: Plugins for Homepage Only, Pt. 2

Posted: Sat Nov 06, 2010 1:24 pm
by garvinhicking
Hi!

Sure, that would also work just fine - I think the result is the same :)


Regards,
Garvin

Re: Plugins for Homepage Only, Pt. 2

Posted: Fri Jan 14, 2011 8:35 pm
by Maccsta
Yes but this coding seems like a more eloquent solution :)