Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-08-04 08:18:42

sbarakat
New Member
Registered: 2011-08-04
Posts: 6
Website

Question on formatting archive page

I am creating an archive page for my posts, each section is split by month so I am making use of <txp:if_different>. However I am having a problem with the first section being split twice.

For example this is my desired result:

<div class="content">
    <h2>Archive</h2>
    <div class="archive">
        <h1>August 2011</h1>
        <div class="archivePost">
            <span class="archiveDate">August 02, 2011</span>
            <span class="archiveTitle"><a href="#">Beef ut irure strip steak meatloaf</a></span> 
        </div>
        <div class="archivePost">
            <span class="archiveDate">August 13, 2011</span>
            <span class="archiveTitle"><a href="#">Ham est nisi laborum jowl sirloin</a></span> 
        </div>
    </div>
    <div class="archive">
        <h1>July 2011</h1>
        <div class="archivePost">
            <span class="archiveDate">July 27, 2011</span>
            <span class="archiveTitle"><a href="#">Tri-tip fatback pork belly brisket esse</a></span> 
        </div>
        <div class="archivePost">
            <span class="archiveDate">July 26, 2011</span>
            <span class="archiveTitle"><a href="#">Tail hamburger dolor</a></span> 
        </div>
        <div class="archivePost">
            <span class="archiveDate">July 25, 2011</span>
            <span class="archiveTitle"><a href="#">Pork loin pork belly qui, laboris sed bresaola brisket aliqua</a></span> 
        </div>
    </div>
  </div>

Instead I am getting this:

<div class="content">
    <h2>Archive</h2>
    <div class="archive">
        <h1>August 2011</h1>
        <div class="archivePost">
            <span class="archiveDate">August 02, 2011</span>
            <span class="archiveTitle"><a href="#">Beef ut irure strip steak meatloaf</a></span> 
        </div>
    </div>
    <div class="archive">
        <h1>August 2011</h1>
        <div class="archivePost">
            <span class="archiveDate">August 13, 2011</span>
            <span class="archiveTitle"><a href="#">Ham est nisi laborum jowl sirloin</a></span> 
        </div>
    </div>
    <div class="archive">
        <h1>July 2011</h1>
        <div class="archivePost">
            <span class="archiveDate">July 27, 2011</span>
            <span class="archiveTitle"><a href="#">Tri-tip fatback pork belly brisket esse</a></span> 
        </div>
        <div class="archivePost">
            <span class="archiveDate">July 26, 2011</span>
            <span class="archiveTitle"><a href="#">Tail hamburger dolor</a></span> 
        </div>
        <div class="archivePost">
            <span class="archiveDate">July 25, 2011</span>
            <span class="archiveTitle"><a href="#">Pork loin pork belly qui, laboris sed bresaola brisket aliqua</a></span> 
        </div>
    </div>
  </div>

The presentation I am using is this:

<txp:if_different>
    <txp:if_first_article><txp:else /></div></txp:if_first_article>
    <div class="archive">
      <h1><txp:posted format="%B %Y" /></h1>
</txp:if_different>
      <div class="archivePost">
      	<span class="archiveDate"><txp:posted format="%B %d, %Y" /></span>
        <span class="archiveTitle"><txp:permlink><txp:title /></txp:permlink></span> 
      </div>
    <txp:if_last_article></div></txp:if_last_article>

I think the issue is that I have a <txp:if_first_article> inside an <txp:if_different>, so for the second post it prints out the header again as the contents differed. However I don’t know what the alternative is. Does anyone have any suggestions?

Offline

#2 2011-08-04 20:25:44

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

Re: Question on formatting archive page

You are probably right, I don’t think if_first_article can work properly inside if_different tags. Something like this might work:

    <txp:if_first_article><div style="display:none;"></txp:if_first_article>
<txp:if_different>
    </div>
    <div class="archive">
      <h1><txp:posted format="%B %Y" /></h1>
</txp:if_different>
      <div class="archivePost">
      	<span class="archiveDate"><txp:posted format="%B %d, %Y" /></span>
        <span class="archiveTitle"><txp:permlink><txp:title /></txp:permlink></span> 
      </div>

I realize this is not a very elegant solution, it’s the lazy way ;) There may be better ones.

Offline

#3 2011-08-05 08:18:59

sbarakat
New Member
Registered: 2011-08-04
Posts: 6
Website

Re: Question on formatting archive page

Thanks, that did it! If the lazy way works I’m game with that ;)

Offline

#4 2011-08-11 11:22:53

arkandos
New Member
Registered: 2011-08-08
Posts: 4
Website

Re: Question on formatting archive page

Hello, I had the same problem on my site. My solution was to set a txp:variable inside the if_different tag and insert the real content inside if_variable tags:

<txp:if_different>
  <!-- <txp:posted format="%B %Y" /> -->
  <txp:variable name="article_archive_different" value="yes" />
<txp:else />
  <txp:variable name="article_archive_different" value="no" />
</txp:if_different>

<txp:if_variable name="article_archive_different" value="yes">
  <txp:if_first_article><txp:else /></div></txp:if_first_article>
  <div class="archive">
  <h1><txp:posted format="%B %Y" /></h1>
</txp:if_variable>

<div class="archivePost">
  <span class="archiveDate"><txp:posted format="%B %d, %Y" /></span>
  <span class="archiveTitle"><txp:permlink><txp:title /></txp:permlink></span> 
</div>

<txp:if_last_article></div></txp:if_last_article>

I wrote this on my mobile, so I cannot guarantee that this code works, but the idea should be clear :)

With this code, you do not have empty html tags above your list. This is a problem if you use e.g. <ul> as list container, which cannot be empty.

PS: Sorry for my bad english (again) …

Last edited by arkandos (2011-08-11 11:36:09)

Offline

#5 2011-08-11 22:40:11

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

Re: Question on formatting archive page

Hey arkandos, what a nice solution! Next time I’ll need to do something like this I will certainly use it!

Offline

#6 2011-08-16 10:58:03

sbarakat
New Member
Registered: 2011-08-04
Posts: 6
Website

Re: Question on formatting archive page

Very elegant solution, thanks arkandos!

Offline

#7 2011-08-16 13:33:48

arkandos
New Member
Registered: 2011-08-08
Posts: 4
Website

Re: Question on formatting archive page

Thanks, Els and sbarakat :)

Offline

Board footer

Powered by FluxBB