Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2010-06-18 02:07:48

deemaho
New Member
Registered: 2010-06-18
Posts: 9

specific Article per Section

Fairly new to TextPattern and while I’ve seen variations of this problem elsewhere, none work for me.

I have a site with multiple Sections, each with 2 to 30 Articles. The main navigation for the site is a list of all Sections, secondary navigation is a list of Article under that active Section.

I’m trying to display a specific Article when a user lands on a Section. If I set the required Article to “Sticky” (and <txp:article status=“Sticky”> in the Page template) none of the other articles show even after their link is clicked. If I don’t use the Sticky option, the Article displayed is either latest/ascending/descending/etc. How do I make specific Articles be the primary ones for their corresponding Sections?

Offline

#2 2010-06-18 03:12:56

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: specific Article per Section

See:

deemaho wrote:

I’m trying to display a specific Article when a user lands on a Section. If I set the required Article to “Sticky” (and <txp:article status=“Sticky”> in the Page template) none of the other articles show even after their link is clicked.

If you want to show stickies at top and lives, you need two seperate article tags. The attributes you use in the tags will filter what the tag shows.

<!--
	If individual article or article list
-->
<txp:if_article_list>
	<!--
		Shows sticky. Article custom won't effect
		context sensitive article tag.
	-->
	<txp:article_custom section='<txp:section />' status="sticky" />
	<!--
		Article shows the actual article list.
	-->
	<txp:article />
<txp:else />
	<!--
		View for individual articles
	-->
	<txp:article />
</txp:if_article_list>

Offline

#3 2010-06-18 03:56:36

deemaho
New Member
Registered: 2010-06-18
Posts: 9

Re: specific Article per Section

Thank you Gocom, however this creates a blog like landing page for the Section. I am trying to display only a single Article that can be specified in by someone editing the site.

E.g. I have Sections Alpha, Beta and Gamma. Under Alpha, there are Articles 1, 2, 3 and 4. I’d like to display only Article 3 in full when the link to Section Alpha is clicked. (From there, a user can click on Article 1, 2, 3, etc. using a separate menu).

Offline

#4 2010-06-18 04:17:09

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: specific Article per Section

deemaho wrote:

E.g. I have Sections Alpha, Beta and Gamma. Under Alpha, there are Articles 1, 2, 3 and 4. I’d like to display only Article 3 in full when the link to Section Alpha is clicked. (From there, a user can click on Article 1, 2, 3, etc. using a separate menu).

Then just remove the second article tag. The same tag structure still applies.

Offline

#5 2010-06-18 13:34:37

deemaho
New Member
Registered: 2010-06-18
Posts: 9

Re: specific Article per Section

Thank you again Gocom, this works for all the Sections except the main home page. The home page of the site stays blank! I’m not sure what I’m doing wrong. I’ve tried changing the status of the Article linked to the home page (Live and Sticky) but nothing appears. Any thoughts?

Offline

#6 2010-06-18 14:24:04

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: specific Article per Section

Hi,

On “Presentation -> Sections”, is there any section set up to “On frontpage? -> Yes”?

You can’t assign articles to “default” (aka “home” or “frontpage”) section, but by enabling the “On frontpage? -> Yes” on one or more sections, articles for those sections will be rendered by any <txp:article /> tag in your “default” page template.

You may also want to try this variation from Gocom’s code above:

<!--
	If individual article or article list
-->
<txp:if_article_list>
	<!--
		Shows just one sticky. The last one.
	-->
	<txp:article status="sticky" limit="1" />
	<!--
		Article shows the actual article list.
	-->
	<txp:article status="live" /> <!-- status attribute is "live" by default, but having it explicitly won't hurt you -->
<txp:else />
	<!--
		View for individual articles
	-->
	<txp:article status="sticky" /> <!-- this one will make Sticky articles to work on their permalink URL (/section/my-stiky-article-title) -->
	<txp:article status="live" />

<!-- 
  The two <txp:article /> tags above may seem a bit redundant,
  but it's currently the only way to make TXP render any kind of article ("sticky" or "live") 
  when visiting its permanent link. Don't worry, you won't get duplicated stuff, 
  as those two <txp:article /> tags are mutually exclusive 
-->

</txp:if_article_list>

La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#7 2010-06-18 17:41:42

deemaho
New Member
Registered: 2010-06-18
Posts: 9

Re: specific Article per Section

maniqui wrote:

On “Presentation -> Sections”, is there any section set up to “On frontpage? -> Yes”?

Yes, I have this enabled but no effect. With the modifications to the code, I still get 2 Articles when viewing a Section. I’m very surprised that a seemingly basic thing is turning out to be so complicated to accomplish.

Offline

#8 2010-06-18 18:14:45

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: specific Article per Section

deemaho:

Please, could you post your page templates for home (usually, the “default” page template) and any section?
Thanks.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#9 2010-06-18 19:25:17

deemaho
New Member
Registered: 2010-06-18
Posts: 9

Re: specific Article per Section

Maniqui: I modified your code to look like:

<txp:if_article_list>
<txp:article status="sticky" limit="1" />
<txp:else />
<txp:article status="live" />
</txp:if_article_list>

But this gave me the same results – home page was blank. Then I went back to Gocom’s code and added a condition (seen in bold)

<div id="main_nav">
<txp:section_list default_title='<txp:text item="home" />' include_default="1" wraptag="ul" break="li" />
</div>

<div id="sub_nav">
<txp:article form="custom_article_list" section="<txp:section />" />
</div>

<div id="sidebar"></div>

<div id="main_content">
<txp:if_section name=”“>
<txp:article_custom allowoverride=“1” status=“Sticky” section=“Homepage” />
<txp:else />
<txp:if_article_list>
<txp:article_custom section='<txp:section />' status="sticky" />
<txp:else />
<txp:article />
</txp:if_article_list>
</txp:if_section>
</div>

This seems to work! Am I doing this right or is there a better way?

Offline

#10 2010-06-19 15:32:01

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: specific Article per Section

Ah, ok, so, you have createad a section named “Homepage”.
You didn’t tell us that before…

One thing. This code:

<div id="sub_nav">
<txp:article form="custom_article_list" section="<txp:section />" />
</div>

Shouldn’t be working properly, as you are using double quotes (") instead of single quotes ('). When nesting TXP tags inside TXP tags, you need to escape them, by using single quotes.

This is the correct version:

<div id="sub_nav">
<txp:article form="custom_article_list" section='<txp:section />' />
</div>

Let’s go on.

This seems to work! Am I doing this right or is there a better way?

If ain’t broken, don’t fix it.
There’s usually several ways to achieve the same in TXP. Some ways are more cleaner, future-proof, scalable than others.

Let’s see. Have you set your “Homepage” section to “On frontpage => yes”? .
If so, this should work too:

<div id="main_content">
<txp:if_section name="">
<txp:article allowoverride="1" status="sticky"  />
<txp:else />
<txp:if_article_list>
<txp:article_custom section='<txp:section />' status="sticky" />
<txp:else />
<txp:article />
</txp:if_article_list>
</txp:if_section>
</div>

I’ve just changed <txp:article_custom allowoverride="1" status="Sticky" section="Homepage" /> to <txp:article allowoverride="1" status="sticky" />.
When on homepage section, <txp:article /> does some default magic: it renders articles from sections that are set to publish its contents on frontpage.

Anyway, I prefer your method (<txp:article_custom allowoverride="1" status="Sticky" section="Homepage" />), as it’s more explicit about what it’s doing.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#11 2010-06-19 23:33:56

deemaho
New Member
Registered: 2010-06-18
Posts: 9

Re: specific Article per Section

Maniqui: First off, your help is greatly appreciated – Thank you!

Yes, I renamed the default “Article” section to “Homepage” to make it easier to understand for the other users who will edit the site.

When nesting TXP tags inside TXP tags, you need to escape them, by using single quotes

I noticed that too and corrected it :) Thank you for picking that out. Yes, I have the Homepage Section set to front.

Another anomaly I’ve noticed is that with this page template, if I try to access a sticky Article directly by itself (either through its URL or through the preview option through the Admin area) nothing is displayed. Shouldn’t the Article (even if it’s sticky) show up because of this statement:

<txp:article_custom section='<txp:section />' status="sticky" />

Offline

Board footer

Powered by FluxBB