Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2020-01-10 09:14:49

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

contextual navigation

I am trying to create a sidebar with related articles but as the tag uses the OR parameter I am doing it from scratch but only 50% of it is working.

<txp:if_article_category number="1">
<txp:article_custom label='Other <txp:section />' labeltag="h4" section='<txp:section />' category='<txp:category1 />' form="my_form" listform="my_list_form" limit="100" wraptag="ul" break="li" class="submenu" />
<txp:else />
<txp:article_custom status limit="99" section='<txp:section />' form="my_form" listform="my_list_form" wraptag="ul" break="li" c10="x" class="submenu" />
</txp:if_article_category>

The first part parses the articles correctly and I am only getting links of articles which belong to the same cat1 as the article I am viewing.

The second part seems to ignore the status, the else statement and the custom_field limitations and lists all articles in the section including those which belong to a category. Am I missing something?

> Edited to add that

  • not all articles in the section belong to a category
  • some articles only belong to category1
  • all articles belonging to category2 also belong to a category1.

Last edited by colak (2020-01-10 09:21:12)


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

Offline

#2 2020-01-10 09:32:15

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

Re: contextual navigation

SOLVED:
Unlike my code above, I had <txp:if_article_category number="1""> online.


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 2020-01-12 07:20:29

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

Re: contextual navigation

I’m bringing this back to life as I’m still struggling with it. I am trying to do the following in the individual articles context.

  1. When visiting an article belonging to a section but not in any category list the rest of the articles of that section which do not belong to any categories
  2. When visiting an article which belongs to cat1 but has no cat2, list the other articles belonging to the section and the particular cat1.
  3. When visiting an article belonging to cat2, list all articles belonging to the same cat2 and and the same cat1 the particular article belongs to.

Interestingly, I have managed the above, because of your help in the forum in an article list context but I am hitting walls when using similar code in the individual articles context. Only the last part of the code, representing point 1 above, returns the right articles. Here’s what I have.

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

<txp:hide>-articles belonging to cat1 but NOT cat2-<txp:hide>

<txp:if_article_category number="1">
<txp:if_variable name="cat2" value="">
<txp:article_custom label='Other <txp:category1 /> <txp:section />' labeltag="h4" section='<txp:section />' category='<txp:category1 />' form="" listform="MyList" limit="100" wraptag="ul" break="li" class="submenu" />
<txp:else />

<txp:hide>-Articles belonging to the same cat1 and cat2-</txp:hide>

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

<txp:else />

<txp:hide>-Articles belonging to the same section but they do not belong to any cat1 or cat2</txp:hide>

<txp:article_custom status section='<txp:section />' c10="x" listform="MyList" form="" limit="999" wraptag="ul" break="li" label='Other <txp:section />' labeltag="h4" />

</txp:if_article_category>

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

Offline

#4 2020-01-12 07:44:22

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

Re: contextual navigation

Alternatively, this works for no cats and cat1 only articles but, understandably, not for cat2+cat1 ones.

<txp:if_article_category number="1">
<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:else />
<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:if_article_category>

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 2020-01-12 15:28:16

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,137
GitHub

Re: contextual navigation

colak, for what it’s worth – I’m enjoying reading about your technical challenges and solutions, so thanks for keeping us informed!

Offline

#6 2020-01-12 16:07:15

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

Re: contextual navigation

gaekwad wrote #321050:

colak, for what it’s worth – I’m enjoying reading about your technical challenges and solutions, so thanks for keeping us informed!

I guess, I’m the first who is trying to reflect the new url structures in txp tags, so, I feel that I am treading in unknown grounds.


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 2020-01-13 07:58:09

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

Re: contextual navigation

The only thing I’ve managed of the weekend is to shorten the second tag combination by 2 lines.

<txp:if_article_category number="1">
<txp:related_articles label='Other <txp:category1 /> <txp:section />' labeltag="h4" section='<txp:section />' category='<txp:category1 />' form="" listform="" limit="100" wraptag="ul" break="li" class="submenu">
<a href="<txp:permlink />" rel="bookmark"><txp:title /></a>
</txp:related_articles>
<txp:else />
<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:if_article_category>

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

Offline

#8 2020-01-13 09:01:56

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,595
Website

Re: contextual navigation

If your article_list case code above is working, could you perhaps do the following for your individual_article case:

<txp:variable name="cat1" value='<txp:category1 />' /> 
<txp:variable name="cat2" value='<txp:category2 />' />

… match='Category1=<txp:variable name="cat1" />, Category2=<txp:variable name="cat2" />' …

but I don’t know if that syntax is valid for match.

Your original code may also depend on you being very careful with your category assigning. The problem cases are Category1 AND Category2 and Category1 AND EMPTY Category2. I think the standard comma in match means the full set of results for both and only by making match more specific can you filter more precisely.

If that doesn’t work, here’s another idea, although I fully expect Oleg or Stef to show a more direct way, but another option might be to first ascertain two comma-separated lists of just the article IDs:

  • a list of all ID#s for section and category1, and
  • a list of all ID#s for section and category2.

Then you can use a few php list/array compare functions to determine the relevant subset of those two lists, e.g.

  • for the AND case, those ID values present in both lists, and
  • for the CAT1 AND NOT CAT2 subtract all the ids in the cat2 list from the the ids in the cat1 list.

See this stackoverflow thread for the first case using array_intersect and for the other case, it’s almost identical, except that you can use array_diff.

Then finally you build your menu from the respective id list…


TXP Builders – finely-crafted code, design and txp

Offline

#9 2020-01-13 10:15:04

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

Re: contextual navigation

Hi Julian,

My problem is that I can not think of a proper syntax.

<txp:variable name="cat1" value='<txp:category1 />' /> 
<txp:variable name="cat2" value='<txp:category2 />' />

<txp:if_variable name="cat1">
	<txp:if_variable name="cat2" value="">
		cat1 without cat2 articles in the section
	<txp:else />
		Articles with the same ca1 and cat2 in the section. ie cat1=physics cat2=staff. The syntax could be
<txp:else />
No cats articles in the section
	</txp:if_variable>
</txp:if_variable>

The syntax for cat1 and cat2 could be

<txp:article_custom limit="999" match="Category1=2, Category2=3" listform="my_form" form="" c10="y" wraptag="ul" break="li" label='Other <txp:category1 /> <txp:section />' labeltag="h4" class="submenu" />

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.


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

Offline

#10 2020-01-13 11:58:48

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Re: contextual navigation

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

<!-- Articles in section belonging to cat1 AND MAYBE cat2 -->
<txp:evaluate test="category1">

    <!-- Articles belonging to cat1 but NOT cat2 -->
    <txp:evaluate not test="category2">
        ...article_custom code...
    <txp:else />

        <!-- Articles belonging to cat1 AND cat2 -->
        ...article_custom code container start...
            <txp:evaluate test="category2">
                ...permlink code...
            </txp:evaluate>
        ...article_custom code container end...

    </txp:evaluate>
</txp:evaluate>

<!-- Articles in section but NO cat1 AND NO cat2 -->
<txp:evaluate not test="category1,category2">
    ...article_custom code...
</txp:evaluate>

Offline

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

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

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 | hblack.art | EMAP | A Sea change | Toolkit of Care
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: 4,595
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

Board footer

Powered by FluxBB