Auto Generate Tags

Michael

Administrator
Staff member
Hi,

Is there a way to auto generate tags from title.
Yes, this is possible but how would you like to use the title?

A way could be to split the title at spaces and use these words than as keyword.

What method are you trying to do?
 

TusharS

New member
Yes, this is possible but how would you like to use the title?

A way could be to split the title at spaces and use these words than as keyword.

What method are you trying to do?
Hi,

As you said, I am planning to split title at spaces and use them as keywords. Would you please help me with that.
 

Michael

Administrator
Staff member
Hi Michael,

Yes, i'm planning to generate auto tags from title when i submit upload. Can you please tell how to do this.

Thank you.
Yes, I'll help you but I require a few days since I'm currently on vacation. Stay tuned :)
 

Michael

Administrator
Staff member
Hi Michael,

Could you please help me now?
Go to app/Http/Controllers/ImagesController.php

Add this line over $sql = new Images;

PHP:
$modify_tags = preg_replace('#\s+#',',',trim(trim($request->title))).','.$request->tags;
and replace $request->title with $modify_tags.

1572695921781.png
 

TusharS

New member
Hi Michael,

Thank you for replying. Sorry for bothering you again. While generating auto tags from title, it is generating an empty tag at the end. Please refer the image.

Screen Shot.PNG
 

Michael

Administrator
Staff member
Hi Michael,

Thank you for replying. Sorry for bothering you again. While generating auto tags from title, it is generating an empty tag at the end. Please refer the image.

View attachment 156
This is caused by the coma which separates the title generated tags with the real tags. I'll fix it as soon as possible. :)
 

Michael

Administrator
Staff member
Hi Michael,

Have you found any solution ?

Thank you.
Replace
PHP:
$modify_tags = preg_replace('#\s+#',',',trim(trim($request->title))).','.$request->tags;
with
PHP:
if($request->tags != '')
    $modify_tags = preg_replace('#\s+#',',',trim(trim($request->title))).','.$request->tags;
else
    $modify_tags = preg_replace('#\s+#',',',trim(trim($request->title)));
$modify_tags = implode(',', array_keys(array_flip(explode(',', strtolower($modify_tags)))));
This code also removed duplicates if there is the same string (= means more or less some text) in the title and tags. Good luck ;)
 
Top