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

NEW Plugin - If Homepage…

Development and Programming

Mark Bowen's avatar
Mark Bowen
12,637 posts
17 years ago
Mark Bowen's avatar Mark Bowen

EDIT - Add Actually the Ternary operation is working fine. I’m just too tired to realise that I was checking against false instead of true. All should work fine hopefully for everyone?

Okay a nice easy one this one in relation to this thread over here.

Please bear in mind that this was written in under 1 minute so hopefully it should do as it says on the tin 😉 I’m still a little confused as I swear that my ternary operator condition in the plugin is working back to front but it seems to be working on my system so hopefully it will elsewhere too. 😉

Usage V1.0.2

{exp:if_homepage}

{if is_homepage}
This is the home-page
{if:else}
This isn't the home-page
{/if}

{/exp:if_homepage}

Usage V1.0.1

{exp:if_homepage}

{if true}
This is the home-page
{if:else}
This isn't the home-page
{/if}

{/exp:if_homepage}

Usage V1.0

{exp:if_homepage}

{if fail}
This isn't the home-page
{if:else}
This is the home-page
{/if}

{/exp:if_homepage}

That’s it basically. Hope it works for everyone and hope it’s of some use.

Best wishes,

Mark

       
Danny T.'s avatar
Danny T.
426 posts
17 years ago
Danny T.'s avatar Danny T.

Mark,

You’re a machine man! Simple, but useful.

       
gridonic's avatar
gridonic
231 posts
17 years ago
gridonic's avatar gridonic

Hey Mark, well done, seems very useful.

Just a tiny remark: in terms of usability, it would make more sense if the syntax was:

{exp:if_homepage}

{if true}
    This is the homepage
{if:else}
    This isn't the homepage
{/if}

{/exp:if_homepage}

Or even

{if {exp:if_homepage}}
    This is the homepage
{if:else}
    This isn't the homepage
{/if}

Don’t know if the latter is possible in EE.

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
17 years ago
Mark Bowen's avatar Mark Bowen

Hiya,

You are absolutely right that I have the condition a bit upside down. Will look at that a bit later on and upload the new version. 😉

Best wishes,

Mark

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
17 years ago
Mark Bowen's avatar Mark Bowen

Okay updated!

Hopefully should work. Let me know if I’ve done something wonky!!

Best wishes,

Mark

       
Danny T.'s avatar
Danny T.
426 posts
17 years ago
Danny T.'s avatar Danny T.

Seriously Mark.. What kind of caffeine do you drink? You’re on here more than I am.. That’s INCREDIBLE.

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
17 years ago
Mark Bowen's avatar Mark Bowen

No caffeine for me. I’m strictly a soft drinks sort of guy. Fly helis so can’t afford to mess with my body too much! 😉

Plus I hate the smell of coffee and other caffeine based products 😊

Is it all working for everyone? The plugin I mean 😊

Best wishes,

Mark

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
17 years ago
Mark Bowen's avatar Mark Bowen

Slight update to the plugin.

Now changed conditional to {if is_homepage} instead of {if true}. Hopefully this is a better fit?

Updated file in top post.

Best wishes,

Mark

       
Ryan M.'s avatar
Ryan M.
1,511 posts
17 years ago
Ryan M.'s avatar Ryan M.

For the record, the newest version is listed as 1.0.2, but the version number in the $plugin_info array still says 1.0.1.

And does every version note require an emoticon?

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
17 years ago
Mark Bowen's avatar Mark Bowen

Hi Ryan,

Thanks for the heads up on the version number. The reason was that I made the swap between 1.0.1 and 1.0.2 quite close between each other and so basically forgot 😉 Fixed now though.

Not too sure what you mean by the emoticons though? Perhaps the ones in the plugin notes? Sorry if that is not the right thing to do? No offence was intended by it.

Best wishes,

Mark

       
AJP's avatar
AJP
311 posts
17 years ago
AJP's avatar AJP

Nice one mark. Just came across a great use for this. And I LOVE that you’re keeping all version available in the parent. I wish more add-ons kept all versions available.

Anywho, good work.

I’d even think it’d be easier if you could create a global variable, only if you’re at the homepage. So, do your query magic to see if you’re at the home page. And then your code could be

{if mb_is_homepage}
TRUE
{if:else}
FALSE
{/if}

without needing the plugin syntax around it.

Anywho… just wishing… wishing up a star!

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
17 years ago
Mark Bowen's avatar Mark Bowen
Nice one mark. Just came across a great use for this.

Excellent. Thanks for the kind words and glad that it has found some uses 😉

And I *LOVE* that you’re keeping all version available in the parent. I wish more add-ons kept all versions available. Anywho, good work.

Yep like to keep everything in the one place making it easier for everyone to find what they are looking for.

I’d even think it’d be easier if you could create a global variable, only if you’re at the homepage. So, do your query magic to see if you’re at the home page. And then your code could be
{if mb_is_homepage}
TRUE
{if:else}
FALSE
{/if}
without needing the plugin syntax around it. Anywho… just wishing… wishing up a star!

Not too sure how I would go about doing that because as far as I know to use a plugin you have to have the surrounding plugin tags. Would be great if that could be done but I don’t know how that is possible.

Anyway glad you found a use for it.

Best wishes,

Mark

       
Ryan M.'s avatar
Ryan M.
1,511 posts
17 years ago
Ryan M.'s avatar Ryan M.

Just to note that this doesn’t work if you’re trying to use Google AdWords. My client has an incoming link like this from certain Google searches:

http://www.site.com/?gclid=CL_H2Jm5x5QCFSQyusyrNbeflg

Even though this is technically still the homepage, the plugin thinks this is not.

       
techops's avatar
techops
18 posts
16 years ago
techops's avatar techops
Just to note that this doesn’t work if you’re trying to use Google AdWords. My client has an incoming link like this from certain Google searches:
http://www.site.com/?gclid=CL_H2Jm5x5QCFSQyusyrNbeflg
Even though this is technically still the homepage, the plugin thinks this is not.

I’ve been struggling with this for quite some time but recently discovered how to use mod_rewrite to combat this. It might not be the best way but it seems to work for me so far…

# Remove session ID's from URL
Options +FollowSymLinks
RewriteCond %{QUERY_STRING} ^(.+)?sid=[a-z0-9]+(&?.*)$
RewriteRule ^(.*)$ /$1?%1 [L,R=301]
       
Dallas Peters's avatar
Dallas Peters
3 posts
15 years ago
Dallas Peters's avatar Dallas Peters

Does this work for EE2? Can’t seem to get it to work. I’m using inbetween the title tag but expressionengine says:

The following tag has a syntax error: {exp:if_homepage} Please correct the syntax in your template.

I’ve used this and it seems to work:

<title>
  {if segment_1==""}
  {site_name}
  {if:else}
  {site_name}{exp:channel:entries rdf="off" limit="1"} - {title}{/exp:channel:entries}
  {/if}
  </title>
       
1 2

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.