Multiple collection pages and popular tags


#1

I have a site with three pages using the “blog” template, so they all have their own collection of children pages. Let’s say they’re called “A” “B” and “C”.

For instance in the page “A” i try to click a popular tag only present in B. It leads to an empty page.

I think I have to separate problems :
The popular tags plugins always uses the current “parent” page as the base url for the link. In the exemple “mysite.com/A/tag:myTag

If I remove the base url in the adress bar to force a full site search of the tag (in the exemple mysite.com/tag:myTag) it search to the default page of the site, which is C.

Do you think I have to change the page hierarchy to add a top page containing the 3 pages and use this page for the tag search ?


#2

Is this the plugin you are using? https://github.com/getgrav/grav-plugin-taxonomylist


#3

Yes, I use the antigrav theme, which uses this plugin


#4

I’m upping this message without answer, because I have exactly the same setup and same issue.

My question is: how do you create different sets of tags for different categories? Or, how do you tell Taxonomylist plugin to use 2 different blog routes, one for each parent page?


#5

@VincentF, @marcocevoli Could it be that you both are trying to solve the ‘problem’ that ‘Popular tags’ is showing tags from blog A + B + C? Would you perhaps like blog A to show only tags defined in A, B to show only tags for B, etc?

If so, you might try using ‘children_only: true’ in ‘/partials/sidebar.html.twig’:

{% include 'partials/taxonomylist.html.twig' with {'base_url':new_base_url, 'taxonomy':'tag', children_only: true} %}

#6

Hi,

thanks a lot! That solves the problem with the sidebar.

On the same subject (I’m putting it here, because it is strictly related, or even the same issue), I’ve also found out that if you’re using “Quark Open Publishing” theme and you add a “featured” tag to a blog post, and you have more than 1 blog section, these blog posts appear as “sticky” on each blog listing page, not only on the corresponding blog page. The code handling this is in blog.html.twig, namely:

{# display posts with 'featured' tag on current blog page - hibbittsdesign.org #}
{% for child in taxonomy.findTaxonomy({'tag': "featured"}) %}
{% include 'partials/blog-list-item.html.twig' with {blog: page, page: child} %}
{% endfor %}

I’m not sure where I should put children_only: true in that code, or if anything else is needed.

The expected result should be:

  • when you have 2 or more pages using Blog template, if you add the featured tag to a blog post, this blog post should only appear in the blog listing page for that Blog page.

Thanks in advance.


#7

@marcocevoli The plugin ‘Popular Tags’ has implemented two different methods for generating a list of taxonomies. One gets all taxonomies defined in the site, the other collects taxonomies occurring in the current blog. The parameter children_only: true defines which method to use.

Note: The parameter children_only: true is a ‘Popular Tags’ only feature.

The block of code you copied, has got nothing to do with ‘Popular Tags’ and hence doesn’t know about the parameter children_only: true. Alas…

You might ask @paulhibbitts if he is willing to implement a blog option to only include ‘featured’ blog items belonging to the current blog.

In the meantime, you could solve the issue as follows:

  • In ‘blog.md’ set child_featured_only: true
  • Copy ‘/user/themes/quark-open-publishing/templates/blog.html.twig’ to ‘/user/themes/mytheme/templates’
  • Replace code you are referring to by:
    {# display posts with 'featured' tag on current blog page - hibbittsdesign.org #}
    {% for child in taxonomy.findTaxonomy({'tag': "featured"}) %}
        {% if page.header.child_featured_only != true %}
           {% include 'partials/blog-list-item.html.twig' with {blog: page, page: child} %}
        {% elseif child.path starts with page.path %}
           {% include 'partials/blog-list-item.html.twig' with {blog: page, page: child} %}
        {% endif %}
    {% endfor %}
    

This will filter out all featured blog items that do not belong to current blog.

To keep the default as in ‘Quark Open Publishing’, the proposed solution will only filter when the ‘child_featured_only’ option is set to ‘true’.


#8

Hi @pamtbaau, thanks for sharing all of your thoughts on this issue - I’ve been learning from your posts too🙂 If @marcocevoli is able to get multiple blogs within one site working (and is willing to share it) I will see if it is a good fit for adding to the Quark Open Publishing too.


#9

Hi again,

after lots of work I’m almost ready to publish my new site. There is a minor glitch, though, that I don’t know how to address:

The Popular Tag section in the sidebar does show the Popular tags for each blog I have on my site (tags used for Blog A are shown on Blog A list page, tags used for Blog B are shown on Blog B list page).

However, if you click on a blog post with the parameter show_sidebar: true, then the Popular tags section is empty.

How should I edit /partials/sidebar.html.twig in order to have the Popular tags both on the list page and each blog post page?


#10

@marcocevoli Are you sure ‘show_sidebar: true’ is the issue?

When parameter ‘children_only: true’ is set for plugin ‘taxonomylist’, it only looks for taxonomies in children of the current page. If the current page is an ‘item’ then there are no children defined. Hence the ‘Popular Tags’ widget is empty…

It would be nice if a page or collection could be passed to taxonomylist.getChildPagesTags()


#11

I didn’t say that “show_sidebar:true” was the issue. I was mentioning this to explain why the blog item had a sidebar, and the Popular Tags section is on this sidebar.

Ok, so, if I got it right, there is no way of setting taxonomylist so that it is correctly populated with the right tags, both in a blog list page and on each blog post item, if you set “children_only: true”, in a configuration with more than one blog?

I’d probably remove the sidebar on blog post items and forget about this. :slight_smile:


#12

If you don’t mind changing the code of the plugin, you might try the following.

As said, when ‘children_only: true’ is set, the method ‘getChildPagesTags()’ is called, which only looks at children of the current page (which is presumed to be the blog). If he current page is a blog ‘item’ there are not children and the ‘Popular Tags’ widget remains empty.

An easy fix is to find the blog parent of the blog item…

Add the indicated lines below into the method ‘getChildPagesTags()’ in file ‘/taxonomylist/classes/taxonomylist.php’ as follows:

public function getChildPagesTags()
{
    $current = Grav::instance()['page'];

    while ($current->template() !== 'blog') {         // Added
        $current = $current->parent();                // Added
    }                                                 // Added

    $taxonomies = [];

The ‘Popular Tags’ widget should now show the tags of the current blog only.

Notes:

  • In the code it is presumed, that all blog items are in child folders of the main blog page. If not, I’m afraid the parent with template ‘blog’ will not be found.
  • Of course, when the plugin taxonomylist gets updated to a new version, the changes will be lost…