Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-09-28 19:03:22

mckooter
New Member
Registered: 2008-09-28
Posts: 2

home page/single article/category page how to make it all work right

okay, i recently purchased and read the book textpattern solutions and must say that i love this cms, but have a question, its probably a super easy answer but im just not seeing it

on the main page of my site i have a single blog post, (just the most recent) , but this page (default) is also used for individual articles as well as category listing,

i cannot figure out how to show different forms for each of those 3 items. i know i can use if_individual_article and if_category_list but im not sure how to setup the if for the homepage. i can call the two forms for the single article and the category list with the if statements but i cannot use the else for the homepage form because theres two else statements (for both the if_individual_article & if_category_list) and i cannot figure out how to basically say:

if its not a category list AND its not a single article: show this form.

that might be confusing, i hope not

edit: can you nest the if statements maybe?

Last edited by mckooter (2008-09-28 19:04:37)

Offline

#2 2008-09-28 19:14:45

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

Re: home page/single article/category page how to make it all work right

mckooter wrote:

if its not a category list AND its not a single article: show this form.

Hi mckooter, yes you can nest if statements of different types (in TXP 4.0.7 you can nest the same tag over and over, but in earlier versions you cannot nest like tags).

The way I tend to do it in the default page template is:

<txp:if_category>
   <h1>Articles on <txp:category /></h1>
   <txp:article limit="10" />
<txp:else />
   <txp:if_article_list>
      <h1>Article list</h1>
      <txp:article limit="8" form="excerpt_list" />
    <txp:else />
      // NOT a category and NOT an article list
      <txp:article />
    </txp:if_article_list>
</txp:if_category>

That might not be exactly what you want in this case, but that general nested layout has stood me in good stead in the past. Hope it helps get you on the right tracks.

EDIT: and you can wrap that lot in a <txp:if_search> / <txp:else /> / </txp:if_search> if you want to be able to handle search results using the same page template as well.

Last edited by Bloke (2008-09-28 19:17:22)


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 2008-09-29 00:16:47

mckooter
New Member
Registered: 2008-09-28
Posts: 2

Re: home page/single article/category page how to make it all work right

thanks, much helpful, now i have a question, last one, can you change the section that hosts the search/categories/individual article listing, or are those three things limited to the default section

Offline

#4 2008-09-29 07:50:18

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

Re: home page/single article/category page how to make it all work right

mckooter wrote:

can you change the section that hosts the search/categories/individual article listing

For search, yes you can by adding the section attribute to point to an alternative location.

Individual articles are native to the section they are assigned when written, so they always appear there unless you override this behaviour using article_custom to grab articles from more than one section.

As for categories, I honestly don’t know. Categories appear to be ‘fake’ sections if you look at the URL (domain.com/category/my-cat-name). I’ve never redirected them elsewhere, but that doesn’t necessarily mean it can’t be done. Perhaps some of our resident tag-geniuses know of a way to use the built-in tags to do this?


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

#5 2008-09-29 11:44:03

thebombsite
Archived Plugin Author
From: Exmouth, England
Registered: 2004-08-24
Posts: 3,251
Website

Re: home page/single article/category page how to make it all work right

For categories you can keep them within the section you are currently viewing. If you are using the <txp:category1 /> and <txp:category2 /> tags within articles you can add a couple of attributes like so <txp:category1 title="1" link="1" this_section="1" /> and if a visitor clicks on the category link the resulting list will display within the current section using whichever page template has been assigned to that section. Use the <txp:if_category> and <txp:else /> tags in that page template to control the display as with Stef’s code above.

If you need to use the <txp:category_list /> tag it also has a “this_section” attribute you can use.

Further information here and here


Stuart

In a Time of Universal Deceit
Telling the Truth is Revolutionary.

Offline

Board footer

Powered by FluxBB