Jump to content

Text Tags


ShadowByte
 Share

Recommended Posts

Hello,

I would like to add tags to my site. Something similar, as you can see in the attachment.

I found this one:
https://processwire.com/blog/posts/pw-3.0.177/

But if I want to create a new field with this type, I can't select this type in the list. It's not in the list. As you can see in the second screen, the "Text Tags" is installed.

What I'm doing wrong?

Thank you in advance.

 

Screenshot 2023-12-01 at 18-28-45 FGFC820 Fanpage.png

Screenshot 2023-12-01 at 18-31-25 Modules • ProcessWire • fgfc820.de.png

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

On 12/5/2023 at 11:54 PM, MarkE said:

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>*}

 

Thanks for the code, I appreciate you 🙂

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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