Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-08-02 15:34:09

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 999
Website

Generating a HTML site map

Hi!

I’m trying to get Textpattern to generate a site map/contents page in HTML. I used the archive page tutorial as a starting point, and it seemed to work at first— but I have added content in several sections since then, and the site map doesn’t update.

Here is what I did:

1. I created a section called site-map that uses the page _map.
2. My _map uses the following line to summon the _site-map article-type form:

<txp:article_custom limit=99999 form="_site-map" />

3. The code of my _site-map form is pretty simple:

<txp:if_different>
	<h2><a href="<txp:site_url><txp:section />"><txp:section /></a></h2>
</txp:if_different>
<txp:if_first_article><ul></txp:if_first_article>
<li><txp:permlink><txp:title /></txp:permlink></li>
<txp:if_last_article></ul></txp:if_last_article>

This form works fine for indexing sections that have multiple “live” articles— but most of my sections are static landing pages that grab only “sticky” content using <txp:if_article_list>. How can I get TXP to include those pages on the site map? Is there a simple way to tell Textpattern to index every section, and include an unordered list of articles for sections that have additional content?

Thanks! I look forward to hearing your feedback.

Offline

#2 2008-08-03 09:36:46

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

Re: Generating a HTML site map

I can’t remember if the “status” attribute takes a comma-separated list or not. It is set to “live” by default but try using status="live,sticky" in the “article_custom” tag.

Last edited by thebombsite (2008-08-03 09:38:44)


Stuart

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

Offline

#3 2008-08-03 19:34:59

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 999
Website

Re: Generating a HTML site map

thebombsite wrote:

try using status="live,sticky" in the “article_custom” tag.

This didn’t affect the output. I also tried searchsticky="1" but got the same result. I think I need to scrap my article form and start over— in addition to not indexing the section landing pages for sections with only one “sticky” article, the HTML output is wrong, because I misused the <txp:if_first_article> and :if_last_article> tags to generate the opening and closing <ul>s. So this:

<txp:if_different>
	<h2><a href="<txp:site_url><txp:section />"><txp:section /></a></h2>
</txp:if_different>
<txp:if_first_article><ul></txp:if_first_article>
<li><txp:permlink><txp:title /></txp:permlink></li>
<txp:if_last_article></ul></txp:if_last_article>

turns into this:

<h2><a href="http://site.dev/section-1/">Section 1 Title</a></h2>
<ul>
     <li><a href="permlink1">Section 1 Live Article a</a></li>

     <li><a href="permlink2">Section 1 Live Article b</a></li> <!-- last article in the section,
but txp:if_last_article knows that there are more articles coming, so no clising </ul> tag -->

     <h2><a href="http://site.dev/section-2/">Section 2 Title</a></h2>

     <li><a href="permlink3">Section 2 Live Article a</a></li>

     <li><a href="permlink3">Section 2 Live Article b</a></li>

     <h2><a href="http://site.dev/section-4/">Section 4 Title</a></h2>

     ... et cetera...
</ul>

Has anyone else used TXP to generate a site-map?

Offline

#4 2008-08-03 19:54:17

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 999
Website

Re: Generating a HTML site map

Ah. I see one. Hmm…

Offline

#5 2008-08-03 21:00:48

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

Re: Generating a HTML site map

johnstephens wrote:

<!— last article in the section, but txp:if_last_article knows that there are more articles coming, so no clising </ul> tag —>

You can try if this works, first install and activate asy_wondertag (won’t be needed anymore in 4.0.7).

Form ‘site-map’:

<txp:if_different>
	<h2><a href="<txp:site_url><txp:section />"><txp:section /></a></h2>
</txp:if_different>
<ul>
<txp:asy_wondertag>
	<txp:article_custom status="sticky" section="<txp:section />" form="site-map-level2" />
</txp:asy_wondertag>
<txp:asy_wondertag>
	<txp:article_custom section="<txp:section />" form="site-map-level2" limit="999" />
</txp:asy_wondertag>
</ul>

Form ‘site-map-level2’:

<li><txp:permlink><txp:title /></txp:permlink></li>

(Not tested, so let me know if it works.)

Last edited by els (2008-08-03 21:03:48)

Offline

#6 2008-08-04 00:51:12

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 999
Website

Re: Generating a HTML site map

Els wrote:

Els wrote:

<li><txp:permlink><txp:title /></txp:permlink></li> (Not tested, so let me know if it works.)

Well, this definitely clears up the list markup problem I was having, but it still won’t show any sections that contain a sticky article rather than live articles. Also, it doubles up the ouput:

Header with link to Section 1

  • Article 1 link
  • Article 2 link
  • Article 3 link
  • Article 1 link (again)
  • Article 2 link
  • Article 3 link

Header with link to Section 2

  • Section 2 Article 1 link

Apart from being labeled as a sitemap, the Wilshire | One link I posted doesn’t really demonstrate what I’m after— it doesn’t map out all the visible site sections for one. I’ve been experimenting with Rob’s superarchive plugin, as well as the cbs_navigation_menu. Superarchive is interesting, but it also seems to ignore sections that don’t have “live” articles. cbcbs_navigation_menu is great for linking to the section landing pages, but not designed to output links to internal articles within each section.

I’m beginning to think that what I’m after can’t be acheived dynamically with Textpattern, and I may just have to hard-code the site map with dynamic portions for sections that update frequently.

I’m surprised that there isn’t a syntax for this:

  1. For each section, link to the section landing page. If there are no live articles in the section go to the next section.
  2. If there are live articles in the section, list each one with a permlink to each article.

I’ll play with it some more— thanks for your help, Els! I welcome any further ideas or feedback!

Last edited by johnstephens (2008-08-04 00:51:55)

Offline

#7 2008-08-04 01:43:32

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 999
Website

Re: Generating a HTML site map

johnstephens wrote:

but it still won’t show any sections that contain a sticky article rather than live articles. Also, it doubles up the ouput…

On further inspection, I see there’s a little more to the method you suggested: It ignored sections without at least one “live” article, but it did include a link to sticky articles for each section that had at least one live article. When I deleted the first <txp:asy_wondertag><txp:article_custom status="sticky" section="<txp:section />" form="site-map-level2" /></txp:asy_wondertag>, that link went away, but the repeated article list remained.

Being in an article form meant that it called the site-map-level2 form for each live article in the section. Since one section has two live articles right now, I got two lists of the same articles.

Hmm. I’m thinking it will be better to hard-code the site map than try to generate it dynamically. I’ll mull it over some more.

Last edited by johnstephens (2008-08-04 01:45:19)

Offline

#8 2008-08-04 07:47:40

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

Re: Generating a HTML site map

I have had this problem too – this is yet another use case where having the ability to do status="sticky,live" would save the day.

Ruud, Robert, please reconsider whether you could reinstated this previous behaviour as requested previously. It would fit nicely alongside the other 4.07 improvements.

Last edited by jakob (2008-08-04 10:43:45)


TXP Builders – finely-crafted code, design and txp

Offline

#9 2008-08-04 09:11:00

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

Re: Generating a HTML site map

Hmm… you’re right, of course that wouldn’t work. Probably 4.0.7 when it comes will be able to do it with the new variable tags.

A workaround would be possible though. Assuming sections ‘1’, ‘2’ and ‘5’ don’t have any live articles, this goes on your page:

<txp:section_list sections="1,2,5" wraptag="" break="h2" />
<txp:article_custom sort="section" form="site-map" limit="999" />

Form ‘site-map’:

<txp:if_article_section name="1,2,5">
<txp:else />
<txp:if_first_article>
<ul style="display: none;">
</txp:if_first_article>
<txp:if_different>
</ul>
<h2><a href="<txp:site_url><txp:section />"><txp:section /></a></h2>
<ul>
</txp:if_different>
<li><txp:permlink><txp:title /></txp:permlink></li>
<txp:if_last_article></ul></txp:if_last_article>
</txp:if_article_section>

It’s not perfect, but it works. The opening/closing ul tags problem will probably disappear in 4.0.7 when we have if_first_section/if_last_section :)

Offline

#10 2008-08-05 06:20:35

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 999
Website

Re: Generating a HTML site map

Thanks again, Els!

For the sites I’m working on right now, each section has internal navigation— so I think <txp:section_list will be the simplest solution. I’m very grateful for your help!

<txp:section_list wraptag="" break="h3" />

By putting this in a sticky article, I can even use my default page for the template. It doesn’t offer the complexity of the nested list approach, but I guess that in terms of Hick’s Law, the simpler solution is better.

Offline

#11 2008-08-05 06:24:32

jstubbs
Member
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: Generating a HTML site map

What about jm’s sitemap?

Offline

#12 2008-08-05 06:32:02

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 999
Website

Re: Generating a HTML site map

What about jm’s sitemap?

I saw that plugin earlier, and I have it installed and active, but I haven’t experimented with it much yet. My sense was that JM’s plugin is for xml sitemaps for search engines, rather than HTML site maps for human users. Am I misunderstanding it? Is there a simple way to parse xml sitemap data meaningfully into HTML?

Thanks for the suggestion!

Offline

Board footer

Powered by FluxBB