Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2014-05-13 09:29:08

raminrahimi
Member
From: India
Registered: 2013-03-19
Posts: 278

show somthing if i'm at home page ( <txp:site_url /> )

how to : if i’m at home show <h1>Welcome</h1> else nothing

i tried :

<txp:if_section>

but it is not working on categories !
example if i’m in a category (index.php?c=news) again it will show <h1>Welcome</h1>

Offline

#2 2014-05-13 09:44:54

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,779
Website GitHub

Re: show somthing if i'm at home page ( <txp:site_url /> )

Try:

<txp:if_category>
   <h1>Category: <txp:category title="1" /></h1>
<txp:else />
   <txp:if_section name="default">
      <h1>You're weclome :-)</h1>
   </txp:if_section>
</txp:if_category>

Edit: code order, sorry.

You can drop the category heading of course and leave it blank between the first if_category and else tags.

Edit2: Or swap the logic round:

<txp:if_section name="default">
   <txp:if_category>
      <h1>Category: <txp:category title="1" /></h1>
   <txp:else />
      <h1>You're weclome :-)</h1>
   </txp:if_category>
</txp:if_section>

The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#3 2014-05-13 10:28:44

etc
Developer
Registered: 2010-11-11
Posts: 5,393
Website GitHub

Re: show somthing if i'm at home page ( <txp:site_url /> )

You’ll have to care also about search string, author, month… Usually, you will use conditionals, but, since <txp:if_month /> tag is missing, another core way could be

<txp:variable name="params" value='<txp:if_section>1</txp:if_section><txp:page_url type="c" /><txp:page_url type="q" /><txp:page_url type="author" /><txp:page_url type="month" />' />

<txp:if_variable name="params" value="">
	<h1>Welcome</h1>
<txp:else />
	... not home page ...
</txp:if_variable>

or more compact

<txp:etc_query globals="pretext" data='<txp:if_section>1</txp:if_section>{?c,q,author,month}'>
	... not home page ...
<txp:else />
	<h1>Welcome</h1>
</txp:etc_query>

Edit: though, $pretext['s'] will contain “default”, which is a bit weird.

Edit: I wonder if this can be used for homepage detection:

<txp:variable name="pfr" value='<txp:page_url type="pfr" />' />
<txp:if_variable name="pfr" value='<txp:page_url />'>homepage<txp:else />...</txp:if_variable>

Last edited by etc (2014-05-13 11:41:04)

Offline

#4 2014-05-13 11:05:11

raminrahimi
Member
From: India
Registered: 2013-03-19
Posts: 278

Re: show somthing if i'm at home page ( <txp:site_url /> )

Done ! thank you

Offline

#5 2015-04-12 07:23:36

raminrahimi
Member
From: India
Registered: 2013-03-19
Posts: 278

Re: show somthing if i'm at home page ( <txp:site_url /> )

hi etc,
problem ! if i put sitename.com/index.php , again it will not works fine :-(
any solution way plz ?

Offline

#6 2015-04-12 09:50:49

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,172
Website GitHub Mastodon Twitter

Re: show somthing if i'm at home page ( <txp:site_url /> )

Couldn’t you use this suggestion by etc?

<txp:variable name="homepage" value='<txp:page_url type="q" />-<txp:page_url type="c" />-<txp:page_url type="author" />-<txp:page_url type="s" />-<txp:page_url type="pg" />' />
<txp:if_variable name="homepage" value="---default-">
Welocome
<txp:else />
</txp:if_variable>

Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

Board footer

Powered by FluxBB