Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#11 2020-01-13 12:47:18

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 8,282
Website

Re: contextual navigation

philwareham wrote #321061:

I think evaluate can help you out maybe? Untested but…

<!-- Articles in section belonging to cat1 AND MAYBE cat2 -->...

That sounds like a good idea but it is not working for me as it returns all articles with category1.

code tested

<txp:article_custom label='Other <txp:category1 /> <txp:section />' labeltag="h4" section='<txp:section />' form="" listform="" limit="100" wraptag="ul" break="li" class="submenu">
<txp:evaluate not test="category2">
<a href="<txp:permlink />" rel="bookmark"><txp:title /></a>
<txp:else />
<a href="<txp:permlink />" rel="bookmark"><txp:title /></a>
</txp:evaluate>
</txp:article_custom>

<txp:evaluate not test="category1,category2">
<txp:article_custom label='Other <txp:section />' labeltag="h4" status limit="99" section='<txp:section />' form="" listform="" wraptag="ul" break="li" c10="x" class="submenu">
<txp:if_custom_field name="status" value="5">
<a href="/<txp:section />/<txp:category1 />/" rel="bookmark"><txp:title /></a>
<txp:else />
<txp:if_article_id>
<span><txp:title /></span>
<txp:else />
<a href="<txp:permlink />" rel="bookmark"><txp:title /></a>
</txp:if_article_id>
</txp:if_custom_field>
</txp:article_custom>
</txp:evaluate>

Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | NeMe @ github | Covid-19; a resource
I do my best editing after I click on the submit button.

Offline

#12 2020-01-13 13:54:47

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,938
Website

Re: contextual navigation

colak wrote #321060:

or maybe not as I am yet to decode the meaning of "Category1=2, Category2=3" recommended by Oleg and working OK in article lists.

As I understand it, the =2 means the second “part” of the browser URL and =3 the third part of the browser URL. For an url like this:


URL:  /section/cat1/cat2/
PART: / (1)   /(2) /(3) /

So =2 means “=cat1” and =3 means “=cat2”.

For an article_list page you will have that. You might also have that for your individual articles if you are sure you will always have /section/cat1/cat2/article-url-title permlinks for articles.

philwareham wrote #321061:

I think evaluate can help you out maybe …

Correct me if I’m wrong, but I thought that if you use …

<txp:evaluate not test="category2">
        ...article_custom code...
</txp:evaluate>

… you need to have a txp:category2 tag in the contained code which it will test against.

Using the query attribute allows you evaluate more complex expressions. e.g. txp:evaluate query="your tag expression here"> ….

You can replicate that if-structure with if_article_category tags to get that logic (I tried that out first) but the tricky bit is getting txp:article_custom to properly filter cat1 AND cat2 and cat1 BUT NOT cat2 logic because I think it matches OR all the time. Maybe the new capabilities of the match attribute can make filtering more capable.

colak wrote #321062:

…articles in section belonging to cat1 AND MAYBE cat2…

That sounds like a good idea but it is not working for me as it returns all articles with category1.

Yes, that is, I think, the same thing: it gets all the articles with category1. Some of those will also have category2. The next bit is then supposed to test whether cat2 is present or not.


TXP Builders – finely-crafted code, design and txp

Offline

#13 2020-01-13 14:05:39

etc
Developer
Registered: 2010-11-11
Posts: 3,934
Website

Re: contextual navigation

Yiannis, what is your working list-page code? There is no reason it wouldn’t be adaptable for individual pages.

And agree with Julian, separate category1/2 attributes would be handy.

Offline

#14 2020-01-13 14:46:24

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 8,282
Website

Re: contextual navigation

Thanks again guys. here’s the article_list (simplified) working code. Apologies if any listforms are missing or they are there where they shouldn’t be.

<txp:if_article_list>

<txp:hide>==================-projects-======================</txp:hide>

<txp:if_section name='<txp:section />'>
<txp:hide>==================-search-======================</txp:hide>
<txp:if_search>
<txp:article pgonly="1" searchall="1" searchsticky="0" />
<txp:if_search_results>
<h3>You searched for <strong><txp:page_url type="q" /></strong>. <txp:search_result_count />.</h3>
<txp:else />
</txp:if_search_results>
<txp:article limit="999" searchall="1" />
<txp:else />


<txp:variable name="cat1" value='txp:page_url type="2" />' /> 
<txp:variable name="cat2" value='<txp:page_url type="3" />' />

<txp:hide>==================-category 1-======================</txp:hide>

<txp:if_category number="1">
<txp:if_variable name="cat2" value="">
<txp:article status limit="30" listform="list_cat2_projects" form="" c10="" />
<txp:else />

<txp:hide>==================-Category 2-======================</txp:hide>

<txp:article_custom limit="1" status listform="" form="">
<txp:if_article_category number="2">
<a href="/<txp:section />/<txp:category1 />/"><txp:category1 /></a> 
</txp:if_article_category>
</txp:article_custom>
<txp:article limit="999" match="Category1=2, Category2=3" form="list_cat_projects" c10="y" />
</txp:if_variable>

<txp:else />

<txp:hide>==================-section landing page-======================</txp:hide>

<txp:article_custom status section="projects" c10="x" form="" limit="999">
<txp:if_article_category>
<a rel="follow" href="/<txp:section />/<txp:category1 />/"><txp:title /></a>
<txp:else />
<a href="<txp:permlink />" rel="bookmark"><txp:title /></a>
</txp:if_article_category>
</txp:article_custom>

</txp:if_category>
</txp:if_search>
</txp:if_section>

</txp:if_article_list>

Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | NeMe @ github | Covid-19; a resource
I do my best editing after I click on the submit button.

Offline

#15 2020-01-13 16:10:48

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 8,282
Website

Re: contextual navigation

Here is my latest effort, based on the working article lists code. It returns the same list (when I view a cat1 or cat1+cat2 articles) as the list generated when I am viewing an article in the section which does not belong to any category.

<txp:variable name="cat1" value='<txp:page_url type="2" />' /> 
<txp:variable name="cat2" value='<txp:page_url type="3" />' />
<txp:hide>==================-category 1-======================</txp:hide>

<txp:if_category number="1">
<txp:if_variable name="cat2" value="">
<txp:related_articles status limit="30" listform="" form="" c10="">
<txp:if_custom_field name="status" value="5">
<a href="/<txp:section />/<txp:category1 />/<txp:category2 />/" rel="bookmark"><txp:title /></a>
<txp:else />
<h3><a href="<txp:permlink />" rel="bookmark"><txp:title /></a></h3>
</txp:if_custom_field>
</txp:related_articles>

<txp:else />

<txp:hide>==================-Category 2-======================</txp:hide>

<txp:article_custom limit="1" status listform="" form="">
<txp:if_article_category number="2">
<a href="/<txp:section />/<txp:category1 />/"><txp:category1 /></a> 
</txp:if_article_category>
</txp:article_custom>
<txp:article_custom limit="999" match="Category1=2, Category2=3" form="" c10="y" label='Other <txp:category1 /> <txp:section />' labeltag="h4">
<a href="<txp:permlink />" rel="bookmark"><txp:title /></a>
</txp:article_custom>
</txp:if_variable>

<txp:else />

<txp:hide>==================-section landing page-======================</txp:hide>

<txp:article_custom status section='<txp:section />' c10="x" form="" limit="999" wraptag="ul" break="li" label='Other <txp:section />' labeltag="h4">
<txp:if_article_category>
<a rel="follow" href="/<txp:section />/<txp:category1 />/"><txp:title /></a>
<txp:else />
<a href="<txp:permlink />" rel="bookmark"><txp:title /></a>
</txp:if_article_category>
</txp:article_custom>

</txp:if_category>

Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | NeMe @ github | Covid-19; a resource
I do my best editing after I click on the submit button.

Offline

#16 2020-01-13 16:31:45

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 8,282
Website

Re: contextual navigation

I just uploaded the particular page I am working on as well as the related forms on github. Note that for the listform above, I only uploaded the partially working version which lists the correct articles when the article only belongs to one category, and when it has no categories at all.


Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | NeMe @ github | Covid-19; a resource
I do my best editing after I click on the submit button.

Offline

#17 2020-01-13 16:55:42

etc
Developer
Registered: 2010-11-11
Posts: 3,934
Website

Re: contextual navigation

I’ve just committed a tweak to enable finer filtering:

<!-- no categories -->
<txp:article_custom exclude="category" />

<!-- Category1 without Category2 -->
<txp:article_custom category='<txp:category1 />' match="Category1" exclude="Category2" />

<!-- matching both categories from URL -->
<txp:article_custom match="Category1=2, Category2=3" />

Something like this should work on individual pages in section/category scheme, please test:

<txp:if_article_category number="1">
	<txp:if_article_category number="2">
		<txp:article_custom section match="Category1=2, Category2=3" form="article_listing" />
	<txp:else />
		<txp:article_custom section match="Category1=2" exclude="Category2" form="article_listing" />
	</txp:if_article_category>
<txp:else />
	<txp:article_custom section exclude="category" form="article_listing" />
</txp:if_article_category>

Offline

#18 2020-01-13 18:18:28

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,776
Website

Re: contextual navigation

Niiice! That’s super slick. I presume this’ll make the custom-fields branch merge, umm, interesting though, hehe. I daren’t try it :)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#19 2020-01-13 18:44:51

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 8,282
Website

Re: contextual navigation

Thanks so much Oleg. Your tweaks and suggestion work just fine with a minor issue when viewing Cat1-only articles. I overcame this easily by using the traditional syntax. I could have used a related_articles tag there but I think that keeping an unlinked title helps with the positioning of the article during surfing. Here is what it absolutely appears to be the working code including some niche parameters I have introduced.

<txp:if_article_category number="1">
	<txp:if_article_category number="2">
		<txp:article_custom section match="Category1=2, Category2=3" form="" listform="" c10="y" wraptag="ul" break="li" label='Other <txp:category1 /> <txp:section />' labeltag="h4" class="submenu" limit="999">
			<txp:if_article_id>
				<span><txp:title /></span>
			<txp:else />
				<a href="<txp:permlink />" rel="bookmark"><txp:title /></a>
			</txp:if_article_id>
		</txp:article_custom>
	<txp:else />
		<txp:article_custom label='Other <txp:category1 /> <txp:section />' labeltag="h4" section='<txp:section />' category='<txp:category1 />' form="" listform="" limit="100" wraptag="ul" break="li" class="submenu">
			<txp:if_article_id>
				<span><txp:title /></span>
			<txp:else />
				<a href="<txp:permlink />" rel="bookmark"><txp:title /></a>
			</txp:if_article_id>
		</txp:article_custom>
	</txp:if_article_category>
<txp:else />
	<txp:article_custom status section form="" listform="" label='Other <txp:section />' labeltag="h4" limit="999" wraptag="ul" break="li" c10="x" class="submenu">
		<txp:if_article_category>
			<txp:if_custom_field name="status" value="5">
				<a href="/<txp:section />/<txp:category1 />/" rel="follow"><txp:title /></a>
			</txp:if_custom_field>
		<txp:else />
			<txp:if_article_id>
				<span><txp:title /></span>
			<txp:else />
				<a href="<txp:permlink />" rel="bookmark"><txp:title /></a>
			</txp:if_article_id>
		</txp:if_article_category>
	</txp:article_custom>
</txp:if_article_category>

Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | NeMe @ github | Covid-19; a resource
I do my best editing after I click on the submit button.

Offline

#20 2020-01-13 19:05:26

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 8,282
Website

Re: contextual navigation

Bloke wrote #321069:

Niiice! That’s super slick. I presume this’ll make the custom-fields branch merge, umm, interesting though, hehe. I daren’t try it :)

Just saw your post:) It is a beauty. I found that I needed the CFs as I created some faux landing pages in order to parse some info from the articles’ CFs but also to place those links on the correct spot of the timeline.

This update requires a learning curve for me but I enjoy witnessing the flexibility of txp surpassing another level.


Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | NeMe @ github | Covid-19; a resource
I do my best editing after I click on the submit button.

Offline

Board footer

Powered by FluxBB