Problems, need help? Have a tip or advice? Post it here.
4 posts Page 1 of 1
Hi, I have 2 clonable templates, let's say blog.php and tags.php
Each cloned page in blog has a direct relation to many pages of tags i.e. any blog page has multiple tags.

I have already listed tags, belonging to the blog page.
Also display counts of pages associated with each tag.

This is in page-view of blog.php (relation is set in blog and named has_tag):
<cms:related_pages field='has_tag' orderby='page_title' order='desc' >
<cms:capture into='count' >
<cms:pages masterpage='blog.php' custom_field="has_tag=<cms:show k_page_name />" count_only='1' />
</cms:capture>
<li><a class="tag" href="<cms:show k_page_link />"><cms:show k_page_title /><sup>&nbsp;<cms:show count /></sup></a></li>
</cms:related_pages>

Now, the idea is the following: show tags, that are not associated with the current page. This will be good for navigating i.e. tag cloud.

I will list at first associated tags with one color and secondly, I want to list the remaining tags with another color.

How would it be constructed? Appreciate any ideas. Thank you!
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
Okay, I got it working.

Here we have samples by @KK. viewtopic.php?f=5&t=8581&p=16352

We are interested in this:
A FEW NOTES:
1. The queries above assumed the relation field was defined in the students template itself.
We can also query for the 'reverse-related' pages i.e. where the relation field is defined in the temlate at the other end of the relationship. For example, assuming there was another template named 'clubs.php' that defined a relation named 'play', we can query the students based on club as follows

List all students who play for 'pegasus':
Code:
Code: Select all
<cms:pages masterpage='students.php'  custom_field="club.php::play=pegasus"  >
    <a href="<cms:show k_page_link />"><h3><cms:show k_page_title /></h3></a>
</cms:pages>

The problem here is a messy explanation, but i deciphered it this way:
'pegasus' is a name of the cloned page of club.php. It has relations with students.php. So, in admin panel on page 'pegasus' we select several students of the whole list of students. I will apply this visualisation to my question:

I will fetch pages from tags.php, but only those, which are *not* related in blog.php on page=current-page-of-blog.

This should be written this way
<cms:pages masterpage='blog.php >
..we are in page-view to fetch each page of blog.php one-by-one..

now let's first list normal associated/related tags:
Code: Select all
      <cms:related_pages field='has_tag'  >
            <cms:show k_page_title /><br>
        </cms:related_pages> 


now let's list *other* tags, which do not belong to our *current page* in blog.php. I will add a variable current_blog_page to make it clearer
Code: Select all
     <cms:set current_blog_page=k_page_name scope='global' />
     <cms:pages masterpage='tags.php' custom_field="blog.php::has_tag!=<cms:show current_blog_page />" >
              <cms:show k_page_name /><br>
         </cms:pages>


</cms:pages>

Tested, works.
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
The next thing is to introduce counting. @KK, can aggregation be used here? If so, then how?

I have now a list of tags, not associated with the current page. But,

1. I don't want to list tags, which are not associated with any blog-page (relation is still defined in blog.php), i.e. don't include tags which lead to nowhere and would not show any blog-pages upon click on them.
2. I would like to list those 'good' tags with a number of pages, associated with each of them.

Maybe some modifications to the code above can be made?
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
Working sub-optimal solution:
Code: Select all
<cms:set current_blog_page=k_page_name scope='global' />
<cms:pages masterpage='blog.php' custom_field="templates.php::has_tag!=<cms:show current_blog_page />" >
                     
   <cms:set count="<cms:pages masterpage='blog.php' custom_field="has_tag=<cms:show k_page_name />" count_only='1' />" />     
     <cms:if count gt '0' >
           <cms:show k_page_title /><sup>&nbsp;<cms:show count /></sup><br>
     </cms:if>
</cms:pages>
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
4 posts Page 1 of 1