Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-02-04 14:15:49

Depot 1
Member
From: Copenhagen
Registered: 2011-01-03
Posts: 24
Website

How do I hide section landing page in my navigation?

Hi,
I’ve tried using the code written by Marie Poulin in the comments for this TXP-Tip page (the fifth entry in the comments) and the code by Kevin Potts from this TXP-tip page

Unfortunately none of these code examples can do what I’m going for: I want to use a specific page for a section landing page, but this page should not appear in the subnavigation.

With Marie’s code the latest article posted will be the section landing page and appear in the subnavigation (if there are more than one article in the section). I can’t figure out how to use a specific article for the landing page regardless of when it was published. And I don’t want the landing page to appear in the subnavigation.

Kevin’s code works perfectly in order to turn a sticky article into the section landing page, but this only works if there are more than one article in the section. With only one article it does’nt show in the navigation.

Kevin mentions using ‘txp:if_individual_article conditional tag’ on the above mentioned TXP-Tip page, but I’m not sure how exactly …

Any help is highly appreciated!!!

Regards
Snorre

Offline

#2 2011-02-04 14:56:44

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

Re: How do I hide section landing page in my navigation?

Hi Snorre

would this help?

<txp:if_section name="your-section-name">
<txp:article_custom id="##">
<txp:body />
</txp:article_custom>
</txp:if_section>

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

Offline

#3 2011-02-04 14:59:02

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: How do I hide section landing page in my navigation?

I’m not sure what you want to do exactly. Let’s say you are using sticky articles for the section landing pages. What should be displayed in the navigation

  • if there is as well a sticky article (landing page) as live articles in a section?
  • if there is only a sticky article in a section?

I don’t want the landing page to appear in the subnavigation.

Do you mean you don’t want a link to /section/sticky-article, or you don’t even want a link to /section/? Or do you only want a link to /section/ if it only contains a sticky article?

Offline

#4 2011-02-04 15:32:15

Depot 1
Member
From: Copenhagen
Registered: 2011-01-03
Posts: 24
Website

Re: How do I hide section landing page in my navigation?

Hi Els,
to clarify:

The navigation is 8 links (level 1) – every link is a section, and the section landing page is a sticky article in that section.
Some of these 8 links have sublinks (level 2) – every sublink is a live article in that section.

  • If there are a sticky article (landing page) and live articles in a section, the navigation will show only the level 1 link (ie the section) by default. When clicked the level 2 links (ie live article titles) appears beneath it.
  • If there is only one article in a section, the level 1 (ie the section) link will appear in the navigation

You can see what I’m trying to accomplish here
In plain HTML it’s no problem off course, but I can’t figure out how to achieve this in TXP.
(‘Forside’, ‘Ydelser’, ‘Vision’ etc. are all sections. ‘Vinduer og døre’, ‘Servicetømrer for kontorer…’ are live articles)

Here is a screen dump of what I got so far using Marie’s code mentioned in original post. The problems here are:
  • The section (level 1) link ‘Ydelser’ appears in the subnavigation.
  • The landing page is not a sticky article in this example, meaning that the most recent article will be the landing page.
Here is a screen dump of what I got using Kevin’s code. The problem is:
  • When only one article is posted in a section and has status=‘sticky’, the page can’t be found.
  • When only one article is posted in a section and has status=‘live’, it appears two times in the navigation – in both level 1 and 2. (See linked example)

Last edited by Depot 1 (2011-02-04 16:16:24)

Offline

#5 2011-02-04 18:23:28

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: How do I hide section landing page in my navigation?

OK, let’s work from Marie’s code. First set the variables (on the page).

<!-- check if there are live articles in this section -->
<txp:variable name="haslivearticle" value='<txp:article_custom section=''<txp:section />'' limit="1" />' />

<!-- check if there is more than one live article in this section -->
<txp:variable name="hasmorelivearticles" value='<txp:article_custom section=''<txp:section />'' offset="1" limit="1" />' />

<!-- check if there are sticky articles in this section -->
<txp:variable name="hasstickyarticle" value='<txp:article_custom status="sticky" section=''<txp:section />'' limit="1" />' />

To display the right article on the section landing page, if I understand you correctly, you need to check if the section has a sticky article (if so, display it on the landing page) or not (display the latest live article on the landing page).

<txp:if_section>
   <txp:if_individual_article>
      <txp:article />
   <txp:else />
      <!-- this is the section landing page -->
      <txp:if_variable name="hasstickyarticle" value="">
         <!-- no sticky article, display latest live article -->
         <txp:article limit="1" />
      <txp:else />
         <!-- display the sticky article -->
         <txp:article status="sticky" limit="1" />
      </txp:if_variable>
   </txp:if_individual_article>
</txp:if_section>

Note that this would still return a 404 for individual sticky article URLs. But since you are not going to link to these pages in the navigation, only to the section landing pages, it won’t be a problem.

The navigation:

<txp:section_list class="subnav" wraptag="ul" break="" form="navbuild" sections="forside,ydelser,vision,mission,socialt-engagement,personen-bag,referencer,kontakt" />

Form ‘navbuild’:

<!-- level 1 links to section landing pages -->
<li<txp:if_section name='<txp:section />'> class="active"</txp:if_section>><txp:section title="1" link="1" />

<txp:if_section name='<txp:section />'>
<!-- level 2 links to articles appear only on their section pages -->

<txp:if_variable name="hasstickyarticle" value="">
<!-- no sticky article in this section, is there more than one live article? -->

   <txp:if_variable name="hasmorelivearticles" value="">
   <!-- no sticky article, only one live article, no level 2 links -->

   <txp:else />
   <!-- no sticky article, more live articles, level 2 links without latest live article -->

      <txp:article_custom section='<txp:section />' form="navbuildlink" wraptag="ul" break="" offset="1" />

   </txp:if_variable>

<txp:else />
<!-- there is a sticky article, level 2 links to all live articles -->

   <txp:article_custom section='<txp:section />' form="navbuildlink" wraptag="ul" break="" />

</txp:if_variable>

</txp:if_section>
</li>

Form ‘navbuildlink’:

<li<txp:if_article_id> class="active"</txp:if_article_id>>
<a href="<txp:permlink />"><txp:title /></a></li>

I hope this does what you want, if not let me know!

Last edited by els (2011-02-04 18:47:43)

Offline

#6 2011-02-05 15:04:59

Depot 1
Member
From: Copenhagen
Registered: 2011-01-03
Posts: 24
Website

Re: How do I hide section landing page in my navigation?

Hi Els,
thank you for your quick and very thorough reply!
I tried your code, but there still was issues if only one sticky article was published in a section. The problem was not your code, but the fact that I placed the content of the webpage in a form, and used <txp:output_form /> on the actual page. When I copied the code into the page instead, it worked perfectly!

I really appreciate the time you spend on helping me out!
And thanks to Colak for your suggestion as well (man, I love this forum!)

Regards
Snorre

Offline

#7 2011-02-05 15:29:28

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: How do I hide section landing page in my navigation?

Depot 1 wrote:

The problem was not your code, but the fact that I placed the content of the webpage in a form, and used <txp:output_form /> on the actual page. When I copied the code into the page instead, it worked perfectly!

Strange, I wouldn’t expect that to make a difference… Anyway, glad you got it to work!

Offline

Board footer

Powered by FluxBB