Jump to content

Recommended Posts

Posted

To create a new field, you need to select a Fieldtype, not an Inputfield. Fieldtypes often have a matching Inputfield, but some support different Inputfields to faciliate the input. The Fieldtype is the part that takes care of storing and loading the data for the field, while the Inputfield provides the UI for entering that data.

In the case of InputfieldTextTags, it doesn't have a matching FieldtypeTextTags, but rather complements the existing Fieldtypes FieldtypeText, FieldtypePage and FieldtypeOptions. So you need to create one of those and then, when you configure the field, choose "Text Tags" as the Inputfield of choice. Once you save it, you will see the configuration options specific to InputfieldTextTags.

  • Like 3
Posted

Hello again,

I still have one question.

So far it works with the tags now. I can also display the tags for each news item individually. This all works great.

What I haven't understood yet is how do I get all the tags that have ever been entered? For example, to display a tag cloud like this?

2103356420_Screenshot2023-12-01at18-28-45FGFC820Fanpage.png.f4b29f776e7f3c68eadb1a5dd52fcfc8.png.f1cb74a5a311dc851d87b1c9912af54d.png
 

Thank you in advance


Edit:

I don't mean the "Predefined options/tags list" from the filed.
With this code, it seems that I only get the "Predefined options/tags list":

$tags = InputfieldTextTags::tagsArray($field)

What about the own tags from users?

 

Posted
6 hours ago, ShadowByte said:

What I haven't understood yet is how do I get all the tags that have ever been entered? For example, to display a tag cloud like this?

Use a Page Reference field for your tags. Then you can do pretty much what you will.

Posted
9 hours ago, MarkE said:

Use a Page Reference field for your tags. Then you can do pretty much what you will.

I just tried it out:
I created a field (Page Reference).
Then added to my template.

Now edited a news item and entered the tag “Test” and saved it.
The "Test" tag was not saved.

There is also no setting that allows users to create their own tags, and I cannot specify tags.

Posted
1 hour ago, ShadowByte said:

Now edited a news item and entered the tag “Test” and saved it.
The "Test" tag was not saved.

There is also no setting that allows users to create their own tags, and I cannot specify tags.

I am assuming you selected 'text tags' as the inputfield type on the field 'input' tab and also selected a parent and template for the tags. Further down that tab, you need to select 'Allow new pages to be created from field' - please note the requirements listed there.

Posted

Thanks a lot. I got it now.

I have one last question. Is there a way to find out how many times a tag has been used? I would like to display the tags in the tag cloud sorted in descending order of frequency.

Posted

You'll have to write some code for that @ShadowByte.

This is my code for my blog tags (in Latte) which I'm sure you can adapt for your purposes (my blogs are in a repeater matix field here):

{var $blogsPage = $page->motif_display_pageref}
{var $blogs = $blogsPage->find("template=MotifDisplay, parent=$blogsPage")}
{var $tags = []}

{foreach $blogs as $blog}
    {foreach $blog->motif_layout_components as $component}
        {if $component->type == 'blog-post'}
            {var $blogTags = $component->motif_blog_tag->explode('title')}
{*            {bd($blogTags, 'blogtags')}*}
            {foreach $blogTags as $blogTag}
                {if !array_key_exists($blogTag, $tags)}
                    {do $tags[$blogTag]['name'] = $blogTag}
                    {do $tags[$blogTag]['count'] = 0}
                {/if}
                {do $tags[$blogTag]['count'] += 1}
            {/foreach}
        {/if}
    {/foreach}
{/foreach}

{* Sort the tags in descending order of frequency so that the most used are at the top *}
{var $tagCount = []}
{foreach $tags as $key => $tag }
    {do $tagCount[$key] = $tag['count']}
{/foreach}
{do array_multisort($tagCount, SORT_DESC, $tags)}

{*<section>*}
    <ul n:foreach="$tags as $tagKey => $arr">
        <li>
            <a href="{$blogsPage->url . 'tag/' . $tagKey}">{$tagKey}</a>
        </li>
    </ul>
{*</section>*}

 

  • Like 2

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...