Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2018-04-03 14:21:37

girlwonderful
New Member
Registered: 2018-04-03
Posts: 6

Changing layout for single articles

Hi guys! I’ve been trying very, very hard to figure this out and treating it like an annoying puzzle I’m trying to solve but I think I’ve hit the wall (I even looked at the old FAQ using waybackmachine! LOL!).

I essentially moved my articles to a section called blog. That page and it’s subsequent category pages look the same and use the same template. Got that handled. However, the single article/permalink page uses that template but I don’t want it to. After much googling I figured out how to make the content actually display using if_individual_article but now I just want it to use a different template altogether. Is this possible?

Also, separate issue but on the blog page, the category permalinks don’t automatically go to blog/?c=CATEGORYNAME, they want to go to sitename/category/CATEGORYNAME – I’m sure this is deadly simple but I’m stuck.

Thanks in advance for any light you can shine on this!

Offline

#2 2018-04-03 14:41:41

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

Re: Changing layout for single articles

Hi, and welcome to the forum. Let’s see if we can get you cross this little hump.

You handle all template (Page) assignments on the Presentation->Sections panel. So what you’re probably seeing is that your default section (front page, and category landing pages usually) is using one Page template, and your blog section is using another. Sometimes this is what you want, sometimes not.

If you visit the Sections panel, you can see what Pages and Styles are assigned to each Section of your site. Click blog to edit that one, and change the dropdowns, then Save and see if it makes a difference.

As you found out, you can treat each Page in two “modes” – list (a.k.a. landing-page) mode, or individual article mode – and you can use the <txp:if_individual_article> tag in your template to detect one or the other.

Hope that helps demystify stuff, but feel free to ask questions here and/or consult the docs (e.g. The Sections panel) to find out more.

P.S. someone (maybe me if I get a chance later) should be able to help you with the category URLs.

Last edited by Bloke (2018-04-03 14:43:08)


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 2018-04-03 15:41:04

girlwonderful
New Member
Registered: 2018-04-03
Posts: 6

Re: Changing layout for single articles

Okay – that did help a smidge so when I go to url/SECTION/PERMALINK – I’m seeing the whole article because I used the conditional. Looping back, is there a way to make THIS use a totally different template than the page it was coming from? I guess is there a conditional for if_individual_article then use page X?

Edited to say thanks! :)

Last edited by girlwonderful (2018-04-03 15:41:25)

Offline

#4 2018-04-03 16:12:45

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,609
Website

Re: Changing layout for single articles

There’s several ways.

From what you describe, you currently have something like:

<txp:if_individual_article>
    <!-- my blog article layout -->
<txp:else />
   <!-- my list page output -->
</txp:if_individual_article>

with all your template code on one page.

One way of breaking down the code into more manageable sections for each page is to use output_form:

<txp:if_individual_article>
    <txp:output_form form="blog_article" />
<txp:else />
   <txp:output_form form="list_view" />
</txp:if_individual_article>

and then to create forms called blog_article and list_view to hold the respective code.

But Textpattern’s standard tag – txp:article – gives you a built-in way to do that that automatically recognises the given context – Is this a landing page, is this a list page filtered by category, or by author, is this an individual article? – based on the url.

With this you’d have (here an expanded example):

<!-- page head -->
<txp:output_form form="page_head" />
<!-- nav -->
<txp:output_form form="page_nav" />
<main>
    <txp:article form="blog_article" listform="list_view" />
</main>
<!-- page foot -->
<txp:output_form form="page_foot" />

txp:article will automatically use the list_view form on list pages, including pages filtered by category, and use the blog_article form on individual article pages. The txp_article tag offers you many more options for how many to list etc. Check the docs.


TXP Builders – finely-crafted code, design and txp

Offline

#5 2018-04-03 16:22:29

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

Re: Changing layout for single articles

Yes, if you are using the same Page template for both your default section and your blog section, then the above is correct: you can use <txp:if_individual_article> to switch between them OR use the power of <txp:article /> to automatically do it.

If, however, you want to use a completely different Page template for your default (home page and category landing pages) and blog (article) sections then you need to visit Presentation->Sections and assign the relevant templates there.

If you go to Presentation->Sections now and look in the table, what Page is assigned to default? And what is assigned to blog? If they’re the same, the situation jakob posted above applies. If you want them to be different, click the blog entry and alter the page it uses from the select list. The two sections will then be treated completely separately.

Last edited by Bloke (2018-04-03 16:23:12)


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

#6 2018-04-03 18:30:02

girlwonderful
New Member
Registered: 2018-04-03
Posts: 6

Re: Changing layout for single articles

Bloke wrote #310591:

Yes, if you are using the same Page template for both your default section and your blog section, then the above is correct: you can use <txp:if_individual_article> to switch between them OR use the power of <txp:article /> to automatically do it.

If, however, you want to use a completely different Page template for your default (home page and category landing pages) and blog (article) sections then you need to visit Presentation->Sections and assign the relevant templates there.

If you go to Presentation->Sections now and look in the table, what Page is assigned to default? And what is assigned to blog? If they’re the same, the situation jakob posted above applies. If you want them to be different, click the blog entry and alter the page it uses from the select list. The two sections will then be treated completely separately.

This was it. THANK YOU BOTH so, so much for this. I messed up the template call and it was the easiest, silliest fix. Thank you!

Offline

#7 2018-04-03 20:19:13

girlwonderful
New Member
Registered: 2018-04-03
Posts: 6

Re: Changing layout for single articles

Okay, I definitely spoke too soon (aka I didn’t scroll far enough to see that what I wanted to happen wasn’t actually happening) :|

And I want to make sure I’m explaining myself correctly (please pardon the mess)

So main page lives here – this is the same page/stylesheet I’d like to use for individual articles

But I want category listings, to use the format on this page – without, ideally having to create a section for each category which I COULD do, there aren’t many but again – how to get the SINGLE entries to use the page from the main?

If that’s what you were describing above, Jakob – my apologies, I was trying to wrap my head around it but umm..yeah. LOL! :D

edited b/c textile is smarter than I am.

Last edited by girlwonderful (2018-04-03 20:22:07)

Offline

#8 2018-04-03 23:24:49

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

Re: Changing layout for single articles

girlwonderful wrote #310593:

So main page lives here – this is the same page/stylesheet I’d like to use for individual articles

But I want category listings, to use the format on this page – without, ideally having to create a section for each category which I COULD do, there aren’t many but again – how to get the SINGLE entries to use the page from the main?

So this is what you could put in Default.

<txp:if_category>

[Category design]

<txp:else />

[Single Page design]

</txp:if_category>

and you should also be able to set Blog to the same Default page since you are only linking to individual articles so it will never be a category listing page.

As Jakob noted, you can put the page designs in miscellaneous forms and just call them with output_form to make your code a little cleaner. It depends on your personal organization preferences.

Offline

#9 2018-04-04 01:12:58

girlwonderful
New Member
Registered: 2018-04-03
Posts: 6

Re: Changing layout for single articles

michaelkpate wrote #310597:

So this is what you could put in Default.

<txp:if_category>...

and you should also be able to set Blog to the same Default page since you are only linking to individual articles so it will never be a category listing page.

As Jakob noted, you can put the page designs in miscellaneous forms and just call them with output_form to make your code a little cleaner. It depends on your personal organization preferences.

Going to try this – thanks all for the help. I’ve been away from TXP for a looong time and trying to wrap my brain around everything has been…challenging :D

Offline

#10 2018-04-04 09:05:20

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,609
Website

Re: Changing layout for single articles

girlwonderful wrote #310587:

Also, separate issue but on the blog page, the category permalinks don’t automatically go to blog/?c=CATEGORYNAME, they want to go to sitename/category/CATEGORYNAME – I’m sure this is deadly simple but I’m stuck.

Try adding section="blog" to txp:category. /category/category-name is the standard situation but once you add the section attribute it should become /blog?c=category-name:

<txp:category title="1" link="1" section="blog" />

or if you are already on that section, you can simply use this_section="1". That makes your code more portable if you decide to rename your “blog” section to “gallery” for example:

<txp:category title="1" link="1" this_section="1" />
girlwonderful wrote #310593:

So main page lives here – this is the same page/stylesheet I’d like to use for individual articles … but I want category listings, to use the format on this page – without, ideally having to create a section for each category.

I think this is a classic case for the regular “txp:article” tag as it does all the figuring out of what appears on which kind of page for you. Your layout also has a common system across the top and bottom. Going back to my earlier example (this time with better, more generic form names).

You might use this in your page template for the blog section:

<!-- nav -->
<txp:output_form form="page_nav" />
<!-- page head -->
<txp:output_form form="page_head" />
<main>
    <txp:article form="single_article" listform="article_list_item" />
</main>
<!-- page foot -->
<txp:output_form form="page_foot" />

with a form called single_article for the single article view and a form called article_list_item for each item in the grid-layout preview. Your forms include only the code for the actual article and one actual preview item.

In the txp_article tag you can use limit="99" and pageby="9" (or whatever you want) to determine how many grid items appear on each page. See the docs.

For the grid layout (It’s hidden now so I can only guess at your markup), you probably need a wrapping container <div …> or two at the beginning and the corresponding closing <div>s at the end. To do that, use if_first_article and if_last_article in your article_list_item form. You can also place your header above the grid in the if_first_article section, along with any special output for a category page, e.g. your article_list_form might look a bit like this:

<txp:if_first_article>
<h2>Photographs<txp:if_category> – <txp:category title="1" /></txp:if_category></h2>
<div class="container grid">
</txp:if_first_article>

    <div class="article-teaser grid-item col-1-of-3">
        <div class="article-image">
            <txp:article_image />
        </div>
        <div class="article-infos">
            <h3><txp:permlink><txp:title /></txp:permlink></h3>
            <txp:excerpt />
        </div>
        <div class="article-meta">
            <txp:posted format="%b %Y" />
            <txp:category title="1" link="1" this_section="1" />
        </div>
    </div>

<txp:if_last_item>
</div> <!-- end .container -->
<!-- pagination links -->
<txp:newer rel="prev">Newer</txp:newer>
<txp:older rel="next">Older</txp:older>
</txp:if_last_item>

In your page template for the default (i.e. home) section – or for any other static section with just one single article in it – it is almost the same as for your blog item except that you leave out the list option and limit it to a single article:

<!-- nav -->
<txp:output_form form="page_nav" />
<!-- page head -->
<txp:output_form form="page_head" />
<main>
    <txp:article form="single_article" limit="1" />
</main>
<!-- page foot -->
<txp:output_form form="page_foot" />

You could assign this page template to any page with just single page information on it, for example, about, contact etc.


TXP Builders – finely-crafted code, design and txp

Offline

#11 2018-04-04 14:27:13

girlwonderful
New Member
Registered: 2018-04-03
Posts: 6

Re: Changing layout for single articles

Thanks again all for the help. I’m hoping to get back to this later today or tomorrow. I really appreciate you.

Offline

Board footer

Powered by FluxBB