Textpattern CMS support forum

You are not logged in. Register | Login | Help

#11 2009-05-21 12:09:00

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,781
Website

Re: Dictating category links order

Okay, I think I’m understanding the dimensions of the problem a bit better now. I can see why my second solution failed — the if_custom_field checks against the current article context, not the articles produced by article_custom, which of course have no context. Only reasonable solutions I can see are my first suggestion or making an article_custom plugin to handle this situation.


Code is topiary

Offline

#12 2009-05-21 12:22:24

Els
Admin
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Dictating category links order

Timid&friendly wrote:

2. Failure I can not separate articles with empty custom_field from articles with used custom_fields, (the empty custom_field articles are allows rendered as well).

Hmm… that’s strange. Give me some time and I’ll try and test that.

Offline

#13 2009-05-21 12:32:17

Timid&friendly
Member
From: The Netherlands
Registered: 2006-05-28
Posts: 252
Website

Re: Dictating category links order

jsoo wrote:

… Only reasonable solutions I can see are my first suggestion or making an article_custom plugin to handle this situation.

The sad thing is that i didn’t understand solution or what a article_custom plugin in fact is :-/

I’ve come up with another approach:-

    <txp:if_article_category name="promise" >
	<txp:variable name="my_var_volgorde" value="<txp:custom_field name='aanverwante_links_volgorde'>" />
	<txp:smd_if field="txpvar:my_var_volgorde" operator="isused">
 	   <txp:article_custom form="MTS_article_list" sort="custom_3 asc" category="promise" aanverwante_links_volgorde="{isused}" offset="0" />
	</txp:smd_if>
    </txp:if_article_category>

What i am trying to do is get the custom_field value as a variable, compare that value to with “{isused}” and if it’s true output only those articles. But I can’t get the variable be parsed by the custom_field attribute name.


I think, therefore I AM, … … er … I think :-?

Offline

#14 2009-05-21 12:42:30

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,781
Website

Re: Dictating category links order

Try this:

<txp:php>
$c1 = $thisarticle['category1'];
$c2 = $thisarticle['category2'];
$rs = safe_rows('ID, Title', 'textpattern', "custom_3 != '' and ((Category1 = '$c1') or (Category1 = '$c2') or (Category2 = '$c1') or (Category2 = '$c2')) order by custom_3 asc");
foreach ( $rs as $r )
echo href($r['Title'], permlinkurl_id($r['ID'])) .'<br />';
</txp:php>

(Oops — edited)

Last edited by jsoo (2009-05-21 12:48:09)


Code is topiary

Offline

#15 2009-05-21 13:10:58

Timid&friendly
Member
From: The Netherlands
Registered: 2006-05-28
Posts: 252
Website

Re: Dictating category links order

That’s nearly there ;-) That is what i am trying to achieve with textpattern tags.

The only thing it’s missing is that the links need to wrap and break using a parent <li> instead of <br />. And I need to offset by 1 link (as i don’t need to show this).
I removed the references to Category1 on line three, as I use this for the parent category.

$c1 = $thisarticle['category1'];
$c2 = $thisarticle['category2'];
$rs = safe_rows('ID, Title', 'textpattern', "custom_3 != '' and ((Category2 = '$c1') or (Category2 = '$c2')) order by custom_3 asc");
foreach ( $rs as $r )
echo href($r['Title'], permlinkurl_id($r['ID'])) .'<br />';
</txp:php>

Last edited by Timid&friendly (2009-05-21 13:13:48)


I think, therefore I AM, … … er … I think :-?

Offline

#16 2009-05-21 13:58:21

Els
Admin
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Dictating category links order

This works for me (on the page). Keep in mind that the code is using my own section and custom field names. The if_article_category part is only to be able to use both categories, if you don’t need that you can remove it.

<txp:if_individual_article>
	<h3>Related articles</h3>
	<ul>
	<txp:article_custom sort="custom_4 asc" section="zoo" category='<txp:category1 /><txp:if_article_category number="2">,<txp:category2 /></txp:if_article_category>'>
		<txp:if_article_id>
		<txp:else />
			<txp:if_custom_field name="sortfield">
				<li><txp:permlink><txp:title /></txp:permlink></li>
			</txp:if_custom_field>
		</txp:if_article_id>
	</txp:article_custom>
	<txp:article_custom section="zoo" sortfield="" category='<txp:category1 /><txp:if_article_category number="2">,<txp:category2 /></txp:if_article_category>'>
		<txp:if_article_id>
		<txp:else />
			<li><txp:permlink><txp:title /></txp:permlink></li>
		</txp:if_article_id>
	</txp:article_custom>
	</ul>
</txp:if_individual_article>

Last edited by Els (2009-08-08 12:29:10)

Offline

#17 2009-05-21 16:03:52

Timid&friendly
Member
From: The Netherlands
Registered: 2006-05-28
Posts: 252
Website

Re: Dictating category links order

Once again thx for all your input. Ik works 99%

This is what i now have.

				<txp:article_custom offset="1" sort="custom_3 asc" category='<txp:category2 />'>
					<txp:if_custom_field name="aanverwante_links_volgorde">
						<li><txp:permlink><txp:title /></txp:permlink></li>
					</txp:if_custom_field>
				</txp:article_custom>
				<txp:article_custom sort="posted asc" aanverwante_links_volgorde="" category='<txp:category2 />'>
					<li><txp:permlink><txp:title /></txp:permlink></li>
			        </txp:article_custom>

The one thing that’s not working 100% is when there are unsorted articles, the offset no-longer works on the sorted articles??????

Last edited by Timid&friendly (2009-05-21 16:04:11)


I think, therefore I AM, … … er … I think :-?

Offline

#18 2009-05-21 16:10:26

Els
Admin
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Dictating category links order

offset="1" sort="custom_3 asc" will skip the first article in the list generated by the tag and it’s attributes, in this case the article with the lowest value in custom_3. Are you using the offset to exclude the current article? Why not use my if_article_id method?

Offline

#19 2009-05-21 16:15:10

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,781
Website

Re: Dictating category links order

Timid&friendly wrote:

The one thing that’s not working 100% is when there are unsorted articles, the offset no-longer works on the sorted articles??????

Right, because the conditional is inside the article tag; the tag itself is picking up all the articles.

There’s probably a native tag-based solution in which the offset is the count of the unsorted articles plus one.


Code is topiary

Offline

#20 2009-05-21 16:30:28

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,781
Website

Re: Dictating category links order

Timid&friendly wrote:

The only thing it’s missing is that the links need to wrap and break using a parent <li> instead of <br />. And I need to offset by 1 link (as i don’t need to show this).

<ul>
<txp:php>
$c1 = $thisarticle['category1'];
$c2 = $thisarticle['category2'];
$rs = safe_rows('ID, Title', 'textpattern', "custom_3 != '' and ((Category2 = '$c1') or (Category2 = '$c2')) order by custom_3 asc limit 1,999");
foreach ( $rs as $r )
echo tag(href($r['Title'], permlinkurl_id($r['ID'])), 'li');
</txp:php>
</ul>

Code is topiary

Offline

Board footer

Powered by FluxBB