Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2014-01-09 11:35:06

monicahu
Member
From: Sydney NSW
Registered: 2009-03-07
Posts: 69

[solved] Archives by dates - listing articles per each month of the yr

To replace the plugin rss_suparchive, I now use <txp:if_different> to show the month then the list of articles posted in the month, and list the articles in an unordered list using <ul> and <li>. To make sure the previous list is closed with an end tag of </ul>, I use <txp: if_first_article>. Likewise, I use <txp:if_last_article> to ensure a </ul> to close the last list.

However I get funny results: the second and others are listed separately from the first article even when they are in the same month of the first one, as if their posted months are different from the first article. Have I used the tags incorrectly here?

On the TXP page called test, I have this

<txp:article_custom section="blog" sort="Posted desc" form="test" limit="999" />

On the TXP form called test, I have this

<txp:if_different>
  <txp:if_first_article>
    <h3><txp:posted format="%B %Y" class="directory3" /></h3>
    <ul>
  <txp:else />
    </ul>
    <h3><txp:posted format="%B %Y" class="directory3" /></h3>
    <ul>
  </txp:if_first_article>
</txp:if_different>

<li><txp:posted format="%d" />: <txp:permlink title='<txp:title />'><txp:title /> ( <txp:author />)</txp:permlink></li>

<txp:if_last_article>
  </ul>
<txp:else />
</txp:if_first_article>

And I get the results like this:

Articles by Dates

December 2013

15: The Visiting King ( Steven Layson)

December 2013

08: When God Became Human ( Steven Layson)
01: Parish Council Planning Day ( Steven Layson)

November 2013

24: The Prodigal Sons ( Steven Layson)
17: Brace Yourselves… ( Steven Layson)
10: Welcome to Thessalonica! ( Steven Layson)
03: People at Prayer ( Steven Layson)

{Edited to enter correct Textile formatting. – Uli}

Last edited by monicahu (2014-01-12 07:11:07)


Monica
Life with God is the purpose.

Offline

#2 2014-01-09 11:48:37

monicahu
Member
From: Sydney NSW
Registered: 2009-03-07
Posts: 69

Re: [solved] Archives by dates - listing articles per each month of the yr

I have also tried this for the first part of code snippet on TXP page but same results are obtained:

<txp:if_different>
  <txp:if_first_article>
  <txp:else />
    </ul>
  </txp:if_first_article>
    <h3><txp:posted format="%B %Y" class="directory3" /></h3>
    <ul>
</txp:if_different>

Last edited by monicahu (2014-01-09 11:51:36)


Monica
Life with God is the purpose.

Offline

#3 2014-01-09 12:01:15

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,315

Re: [solved] Archives by dates - listing articles per each month of the yr

if_different is a real beast ;)

IIRC, if_different can only work on one TXP tag contained. So you need to exchange the if_different and if_first_article tags, duplicating if_different in each part of the if_first_article switch.

Try

 <txp:if_first_article>
    <txp:if_different><h3><txp:posted format="%B %Y" class="directory3" /></h3>
    <ul></txp:if_different>
  <txp:else />
    <txp:if_different></ul>
    <h3><txp:posted format="%B %Y" class="directory3" /></h3>
    <ul></txp:if_different>
  </txp:if_first_article>

EDIT: Added first opening if_different.

Last edited by uli (2014-01-09 12:02:33)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#4 2014-01-09 12:15:23

monicahu
Member
From: Sydney NSW
Registered: 2009-03-07
Posts: 69

Re: [solved] Archives by dates - listing articles per each month of the yr

uli wrote #277960:

if_different is a real beast ;)

IIRC, if_different can only work on one TXP tag contained. So you need to exchange the if_different and if_first_article tags, duplicating if_different in each part of the if_first_article switch.

Try

<code> &lt;txp:if_first_article&gt;...

Thank you Uli. Have tried your method but no luck at all – same results.


Monica
Life with God is the purpose.

Offline

#5 2014-01-09 12:39:14

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,315

Re: [solved] Archives by dates - listing articles per each month of the yr

monicahu wrote #277961:

Thank you Uli. Have tried your method but no luck at all – same results.

Strange.

I’ve tried it here, and it works pretty well. Have you thought of the cache?


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#6 2014-01-09 13:40:07

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,315

Re: [solved] Archives by dates - listing articles per each month of the yr

Sorry, you’re right, my logic failed, whew. (And the test failed for lack of an apt database.)
Off for work now, but you could try if this article on TXP Tips helps. It would let you “extend the validity” of if_different’s evaluations.


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#7 2014-01-09 21:01:24

etc
Developer
Registered: 2010-11-11
Posts: 5,393
Website GitHub

Re: [solved] Archives by dates - listing articles per each month of the yr

What about this?

<txp:variable name="date" value='<txp:if_different><txp:posted format="%B %Y" class="directory3" /></txp:if_different>' />
<txp:if_variable name="date" value=""><txp:else />
	<txp:if_first_article><txp:else /></ul></txp:if_first_article>
	<h3><txp:variable name="date" /></h3>
	<ul>
</txp:if_variable>
<li>...article stuff...</li>
<txp:if_last_article></ul></txp:if_last_article>

Edit: oops, that was actually the tip Uli cited above.

Last edited by etc (2014-01-09 21:18:34)

Offline

#8 2014-01-10 12:56:26

monicahu
Member
From: Sydney NSW
Registered: 2009-03-07
Posts: 69

Re: [solved] Archives by dates - listing articles per each month of the yr

Before I saw uli and Oleg’s suggestion, I had dreamed up a dumb way.

On the calling page I added a pair of <ul> tags around the article_custom for the first and last articles, like this:

        <h2>Articles by Dates</h2>

<txp:hide>In order to make if_different work properly, a dummy <ul> is included here for the first article and another </ul> for the last article</txp:hide>

        <ul><txp:article_custom section="blog" sort="Posted desc" form="test" limit="999" /></ul>

and abandoned the use of if_first_article and if_last_article, like this:

<txp:if_different></ul><h3><txp:posted format="%B %Y" class="directory3" /></h3>
    <ul></txp:if_different>

<li><txp:permlink title='<txp:title />'><txp:posted format="%d" />: <txp:title /> ( <txp:author />)</txp:permlink></li>

Yes, the code is not clean with a pair of null <ul></ul>

Will try Uli’s method.

Edit: Tried Uli’s and Oleg’s method – it also worked. Thank you both of you. So, which one is better – the short one which is quick and dirty or the long one which is more proper ?

Last edited by monicahu (2014-01-10 13:35:39)


Monica
Life with God is the purpose.

Offline

#9 2014-01-10 13:10:50

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,315

Re: [solved] Archives by dates - listing articles per each month of the yr

monicahu wrote #277996:

Will try Uli’s method.

That mention belongs on Els’ medal chest ;)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#10 2014-01-10 13:31:44

monicahu
Member
From: Sydney NSW
Registered: 2009-03-07
Posts: 69

Re: [solved] Archives by dates - listing articles per each month of the yr

Now I have the next problem to tackle. How would I add an article count after the period as if:

Dec 2013 [3]

15: The Visiting King ( Steven Layson)
08: When God Became Human ( Steven Layson)
01: Parish Council Planning Day ( Steven Layson)

as well as expand and collapse the article list when click the period which has a markup using <h2>.

I used a modified version of Oleg’s script but it didn’t work. I must modified the script incorrectly :(

<script>
$(function () {
	$("h3.directory3">a).after(function(){
		var count = $(this).parent().children ("ul").children("li").length;
		return (count ? "&nbsp;["+count+"]" :"");
	}).click(function(){
		$(this).parent().children("ul").toggle();return false;
	}).click();
});
</script>

on the form I have the codes modified as:

<txp:if_different></ul><h3 class="directory3"><a href="#"><txp:posted format="%B %Y" /></a></h3>
    <ul></txp:if_different>

<li><txp:permlink title='<txp:title />'><txp:posted format="%d" />: <txp:title /> ( <txp:author />)</txp:permlink></li>

Last edited by monicahu (2014-01-10 13:38:44)


Monica
Life with God is the purpose.

Offline

#11 2014-01-10 14:27:45

etc
Developer
Registered: 2010-11-11
Posts: 5,393
Website GitHub

Re: [solved] Archives by dates - listing articles per each month of the yr

First, you’ve got a typo in the selector ($("h3.directory3">a) should be $("h3.directory3>a")). Next, <ul> is no more a child of a.parent(), but its sibling, so I’d try

<script>
$(function () {
	$("h3.directory3>a").after(function(){
		var count = $(this).parent().next("ul").children("li").length;
		return (count ? "&nbsp;["+count+"]" :"");
	}).click(function(){
		$(this).parent().next("ul").toggle();return false;
	}).click();
});
</script>

Offline

#12 2014-01-10 14:56:22

monicahu
Member
From: Sydney NSW
Registered: 2009-03-07
Posts: 69

Re: [solved] Archives by dates - listing articles per each month of the yr

etc wrote #278007:

First, you’ve got a typo in the selector ($("h3.directory3">a) should be $("h3.directory3>a")). Next, <ul> is no more a child of a.parent(), but its sibling, so I’d try

<span class="pun">&lt;</span><span class="pln">script</span><span class="pun">&gt;</span><span class="pln">...

It worked! Thank you again, Oleg !!! (3 cheers).

So, which solution is better (see my post on page 1)

monicahu wrote #277996:

Before I saw uli and Oleg’s suggestion, I had dreamed up a dumb way.

On the calling page I added a pair of <ul> tags around the article_custom for the first and last articles, like this:

&lt;h2&gt;Articles by Dates&lt;/h2&gt;...

and abandoned the use of if_first_article and if_last_article, like this:

Last edited by monicahu (2014-01-10 14:59:02)


Monica
Life with God is the purpose.

Offline

Board footer

Powered by FluxBB