Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-02-28 16:31:54

Zanza
Plugin Author
Registered: 2005-08-18
Posts: 699
Website

bos_if_cat_parent

Version 0.2: A simple plugin offering now 5 conditional:

txp:bos_if_cat_parent is=“name”,

txp:bos_if_cat_parent_not is=“name”,

Added: txp:bos_if_p

Added: txp:bos_if_not_p

Now you can control the parsing of block of code if there is a $p set or not (useful in paging, i.e. paging articles or image galleries, generated by image_display or bos_image_display tags.

Bonus tag: I also added bos_if_not_category, just to not make another plugin… :)

Download: v.0.2
You can also define the type of category (article, image, link). I needed this for another plugin, I hope some one find it useful.

Please report any bug.

Z-

Last edited by Zanza (2008-04-28 09:30:15)

Offline

#2 2006-03-05 14:49:40

Zanza
Plugin Author
Registered: 2005-08-18
Posts: 699
Website

Re: bos_if_cat_parent

Updated the plugin with 2 new conditionals:

bos_if_p and bos_if_not_p, for parsing or not parsing in case of paginated things (global $p), like in the image galleries or paginated articles.

See first post for download.

Z-

Offline

#3 2006-03-06 03:36:54

Jeremie
Member
From: Provence, France
Registered: 2004-08-11
Posts: 1,578
Website

Re: bos_if_cat_parent

Can he browse recursively to find a parent ?

As in :

  • A
    • B
      • C

A would be a recursive parent of C.

Offline

#4 2006-03-06 09:32:57

Zanza
Plugin Author
Registered: 2005-08-18
Posts: 699
Website

Re: bos_if_cat_parent

Jeremie: no, at the moment it can’t.

It finds if the parent is (or is not) the one you specify.

Anyway in a site I use a 3 level nesting category, in a way that is difficult to explain. I’d like to improve that: if you have suggestions or use example, please tell here.

Bye

Z-

Offline

#5 2006-03-06 11:31:35

Jeremie
Member
From: Provence, France
Registered: 2004-08-11
Posts: 1,578
Website

Re: bos_if_cat_parent

You could add an attribute recurse that would accept an number or a text for all.

txp:bos_if_cat_parent is=”name” recurse="2" would check on the parent and the parent’s parent for example.

txp:bos_if_cat_parent is=”name” recurse="all" would go all the way up the the first level to check if name is somewhere here.

I don’t remember the TXP’s SQL structure on that however, I don’t know if that would be too heavy to do.

Offline

#6 2006-03-06 15:06:19

igner
Plugin Author
Registered: 2004-06-03
Posts: 337

Re: bos_if_cat_parent

I haven’t looked at this plugin, but it should be relatively easy to determine whether a category is a subcategory at any level:

Assuming the tag were <txp:bos_if_cat_parent is="name" recurse="all">, the current category is stored in $category, and the test category is in $name, you could do something like:
<code>
$out = false; //initialize $out
$child = safe_row(‘parent, lft, rgt’, ‘txp_category’, “name = ‘$category’”);
if ($child[‘parent’]==$name)
{
$out = true; //or whatever you want to return
} else {
$parents = safe_rows(‘name’, ‘txp_category’, “lft < {$child[‘lft’]} and rgt > {$child[‘rgt’]}”;
if (in_array($name, $parents[‘name’]))
{
$out = true;
}
}
return $out;
</code>

To handle the arbitrary depth, you could conceivably grab ‘parent’ in addition to ‘name’ in the parents array and iterate through n times. But I’ll leave that to you to sort out :)


And then my dog ate my badger, and the love was lost.

Offline

#7 2006-03-07 11:45:49

Zanza
Plugin Author
Registered: 2005-08-18
Posts: 699
Website

Re: bos_if_cat_parent

Jeremie and Igner, thank for the sugggestions and for the code example.

This week I’m working out of office, so I’ll give it a try in the next week.

Bye!

Z-

Offline

Board footer

Powered by FluxBB