Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2014-06-11 08:48:14

Bongo-man
Member
Registered: 2009-03-18
Posts: 243

[SOLVED] conditional active category, for different index pages

Is there a way to get conditional active categories?

What I mean, my purpose, is to find a way so that different index (section) pages (each one listing some categories) could have a specific active category, so that when you open each one of the index pages, a specific category is already selected. I’m trying to get all this with a same template.

In my case the parent category of every group of (categories) has (already) the name matching that of the relative index page; but till now I can’t find a way to profit it, in order to get what I need.

So, in my opinion the start point should be some sort of conditional expression, allowing to switch the active category name, according to each index page name (or parent category name, because they match each other).

- The only thing that could sound ‘strange’ (an original error) is that in this website the article listing section (page) is not the same of the articles section; that is each group of articles is listed in a specific page whose section name is not their section name.

I hope having been clair in my explaination.

Till now, I have got a specific group of article-categories listed in every index page (all this because each parent category matches the name of a relative section -> index page), but no active category is available; so that when I open each index page, all the articles of the site are listed, until I choose a category from the menu. When I select a category I get the relative articles (only) are listed.

I get all that by means of these TXP expressions (each one in a module):

In the side menù:

<tr>
<td class=“tabelline2”>
<span class=“titolo”>Categorie di articoli</span>
</td>
</tr>

<txp:category_list parent=’<txp:section />’ exclude=’<txp:section />’ wraptag=“p” break=”“>
<p<txp:if_category name=’<txp:category />’> class=“active”</txp:if_category>> <——————————- This is the part to customize

<tr>
<td class=“tabelline” style=“background-color: white;” onmouseover=“this.style.background=’#f4efd2’” onmouseout=“this.style.background=‘white’”>
<txp:category title=“1” link=“1” class=“catlink” />
</td>
</tr>

</p>
</txp:category_list>

In the center of the page:

<txp:article_custom category=’<txp:category />’ section=“each page section, also matching a parent category” sort=“Posted desc” wraptag=“div” break=“br” class=“news” limit=“50”>

<div class=“articletitle”><txp:title /></div>

<div class=“image”><txp:article_image thumbnail=“1” />
<txp:excerpt /></div>

Thanks, in advance

Last edited by Bongo-man (2014-06-12 10:02:15)

Offline

#2 2014-06-11 12:07:05

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,171
Website GitHub Mastodon Twitter

Re: [SOLVED] conditional active category, for different index pages

Hi

There seems to be too much info in your post and it becomes confusing. I guess the important part is

<txp:category_list parent='<txp:section />' exclude='<txp:section />' wraptag="p" break="">
<p<txp:if_category name='<txp:category />'> class="active"</txp:if_category>>something</p>
</txp:category_list>

Would example 3 from the tag reference be of help? Otherwise can you be slightly less verbose and focus more on the support request? I’m sure we will sort it out.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#3 2014-06-11 14:36:57

Bongo-man
Member
Registered: 2009-03-18
Posts: 243

Re: [SOLVED] conditional active category, for different index pages

The example 3 is what I used (changing li with p), but I don’t know if I did the right way (it lists the categories of a same category list, but doesn’t activate the category I’ve choosen (the first category_listed).
Really I don’t know where the category (needing to be activated) must be placed
The same occurred with expression you reported in your answer.

I’ve the first expression & similarly the other, as below:

<tr>
<td class=“tabelline2”>
<span class=“titolo”>Categorie di articoli</span>
</td>
</tr>

<txp:category_list parent=“parent1” exclude=“parent1” wraptag=“p” break=”“>
<p<txp:if_category name=“1th-category-listed”> class=“active”</txp:if_category>>

<tr>
<td class=“tabelline” style=“background-color: white;” onmouseover=“this.style.background=’#f4efd2’” onmouseout=“this.style.background=‘white’”>
<txp:category title=“1” link=“1” class=“catlink” />
</td>
</tr>

</p>
</txp:category_list>

If the expression above work I could perhaps reply them in a multiple conditional expression

Besides considering that each ‘parent’ category matches a relative listing-page section, it could be useful to get a more compact expression in a same template for every index page (listing groups of directories) and leave the first of them active. Schematically should be something like this:

<txp:category_list parent=’<txp:section />’ exclude=’<txp:section /> wraptag=“p” break=”“>
<p<txp:if_category name=“1th-category-listed”> class=“active”</txp:if_category>>

Active class could be the first category of each category list (whose names match those of each section page in which every category-list displays the categories).

Last edited by Bongo-man (2014-06-11 14:41:09)

Offline

#4 2014-06-11 15:03:05

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,171
Website GitHub Mastodon Twitter

Re: [SOLVED] conditional active category, for different index pages

So (excuse me if i got it wrong) you want the 1st category listed to have the active class?

If this is the case, the code above would not work. I am wondering if one of etc’s plugins or zem_nth would do the job.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#5 2014-06-11 15:28:19

Bongo-man
Member
Registered: 2009-03-18
Posts: 243

Re: [SOLVED] conditional active category, for different index pages

Yes sure, the first category in a category list.

Then I would have tried to activate the ‘active_class’ in each <txp:category_list /> so that the first category display in the each list with a different colour.

Sorry, isn’t that an active category?

Then I will try this plugin, if there is no other way.
Hope it works, I’m in the middle of a ‘river’: the menus display well in each category-list and work; but no category is activated by default and each page displays all the articles of the web site!
———————-
Anyway I would only need to achieve that not all of the articles be displaied (not necessarely I need a default category displayed); so that it could usefull, as well, simply to prevent all the articles are listed and instead, by default, get listed the last articles of all the categories (whose parent category matches the section-page name).

Thank you very much

Last edited by Bongo-man (2014-06-11 15:44:35)

Offline

#6 2014-06-11 16:47:58

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,171
Website GitHub Mastodon Twitter

Re: [SOLVED] conditional active category, for different index pages

The active category is normally the one the page is parsing. ie if you are on category page called dogs the dogs category will be the active one even though the cats category is listed above it.

Rethinking about it, you may not need any plugins. There is the <txp:if_first_category> native tag which you could take advantage of using the untested code below.

<txp:category_list parent='<txp:section />' exclude='<txp:section />' wraptag="" break="">
<txp:if_first_category>
<p class="active"><txp:category link="1" /></p>
<txp:else />
<p><txp:category link="1" /></p>
</txp:if_first_category>
</txp:category_list>

Last edited by colak (2014-06-11 16:53:04)


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#7 2014-06-11 20:18:54

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

Re: [SOLVED] conditional active category, for different index pages

To style the first category of the list you could just use CSS :first-child selector. If you really want to cheat and define a “current” category, here is a tiny public-side plugin:

register_callback('abc_cat', 'pretext_end');

function abc_cat() {
	global $pretext;
	if(empty($pretext['c'])) switch($pretext['s'])
	{
		case 'pets' : $pretext['c'] = 'cats'; break;
		// add other cases here
	}
}

This will make txp think it is on s=pets&c=cats page when you land on s=pets page, so <txp:category /> will output “cats”.

Offline

#8 2014-06-12 07:13:44

Bongo-man
Member
Registered: 2009-03-18
Posts: 243

Re: [SOLVED] conditional active category, for different index pages

This expression allow only to display a different colour for the first category in the list, anyway, thank you for you answers.

Finally I’ve decided to achieve the necessary substitution of the initial complete listing of all the articles of the site (in each section-page), displaying (by default) in each of them, (only) all the articles of each parent category (whose name matches that of the relative section page) limiting them to 3 articles by each category.
I’ve got all that by means of this expression:

<txp:category_list parent=’<txp:section />’ exclude=’<txp:section />’ wraptag=“p” break=“p”> <txp:category title=“1” wraptag=“p” class=“titoloart” /> <txp:article_custom category=’<txp:category />’ wraptag=“p” break=“p” limit=“3”> <txp:permlink><txp:title /></txp:permlink> – <i>Publication date:</i> <txp:posted wraptag=“em” /> </txp:article_custom>
</txp:category_list>

The actual problem is that I can no more switch (by means of the lateral menu) in order to alternatively display all the articles of only one category, that I could previously get by means of the expressions listed in my antecedent messages.
If necessary, I don’t need to get the initial listing by category, what I need is only to get each section page lists only articles from the relative (and matching for his name) parent category with alternative switching to all the articles of only one of the category, selecting one of them in the lateral menu.
I’m trying, but till now no results! :)

Maybe I must put some conditional staments in the center of the page to switch between alternative articles displaying, but I don’t know which

Last edited by Bongo-man (2014-06-12 08:00:51)

Offline

#9 2014-06-12 08:06:38

Bongo-man
Member
Registered: 2009-03-18
Posts: 243

Re: [SOLVED] conditional active category, for different index pages

ETC, excuse me I didn’t realize of your answer, during last night I’ve realized is better to display (in each section page; I have 11 each one with many articles), all the articles of the relative parent category (matching in the name with the relative section page). So early this morning I’ve posted a new message, on the basis of what I have made during the night. Anyway thank you very much for your answer.

Last edited by Bongo-man (2014-06-12 08:07:12)

Offline

#10 2014-06-12 08:19:42

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,171
Website GitHub Mastodon Twitter

Re: [SOLVED] conditional active category, for different index pages

Looking at your code wraptag="p" break="p" will produce invalid html


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#11 2014-06-12 08:26:38

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

Re: [SOLVED] conditional active category, for different index pages

It’s okay, no problem. Is this what you are looking for:

<txp:category_list parent='<txp:section />' exclude='<txp:section />' wraptag="" break="">
	<txp:category title="1" wraptag="p" class="titoloart" />
	<txp:if_category>
		<txp:if_category name='<txp:category />'>
			<txp:article_custom category='<txp:category />' wraptag="p" limit="999">
				<txp:permlink><txp:title /></txp:permlink> – <i>Publication date:</i> <txp:posted wraptag="em" />
			</txp:article_custom>
		</txp:if_category>
	<txp:else />
		<txp:article_custom category='<txp:category />' wraptag="p" limit="3">
			<txp:permlink><txp:title /></txp:permlink> – <i>Publication date:</i> <txp:posted wraptag="em" />
		</txp:article_custom>
	</txp:if_category>
</txp:category_list>

Last edited by etc (2014-06-12 08:38:44)

Offline

#12 2014-06-12 08:38:27

Bongo-man
Member
Registered: 2009-03-18
Posts: 243

Re: [SOLVED] conditional active category, for different index pages

Ok, removed (it was an oversight) but no change.

My problem is that there is a natural flow of (all the) articles of the site, I can’t select (by parent category) in a way that doesn’t prevent the alternative displaying of the active category articles, acting on the side menu.
———————-
Sorry I didn’t realize (again) of Etc’s answer, now I look at it; thank you Etc.

Last edited by Bongo-man (2014-06-12 08:46:18)

Offline

Board footer

Powered by FluxBB