Please @Gerardcole I Have Search And Ask From Many People Please Help Me With It This Is My Showtopic

Loading...
showtopic.php (7.5KB) [0 view]
  • Date: Aug 05, 2016
  • Edited: Aug 05, 2016 by Ade360

I mean forum tags like yours.

when i want to create a post i will add tags with commas

  • Date: Aug 05, 2016
  • Edited: Aug 05, 2016 by Gerardcole

Okay. I'm sorry its not something i can implement for you but you gotta do it on your own. I'll try to use the pbnl names i can remember.

Steps involved:

  1. Accepting the tags

  2. Cleaning and removing duplicates

  3. Storing the cleaned tags

  4. Parsing tags as their repective urls.

  5. Fetching articles of a particular tag

1. Accepting Tags


This one is quite simple just the regular HTML form.

HTML Code
<input type="text" name="post_tags">


2. Cleaning and Removing Dupiicates


This function should be of help...


PHP Code
function clean_post_tags ( $tags ) {
    $clean_tags = '';
    if ( $tags ) {
        $tag_list = array_unique(array_map('trim', array_filter(explode(',', $tags))));
        foreach ( $tag_list AS $this_tag ) {
            $this_tag = preg_replace("/[^A-Za-z0-9 _\.\-]/", "", trim($this_tag));
            if ( !empty($this_tag) AND strlen($this_tag) <= 50 ) {
                if ( empty ( $clean_tags ) ) {
                    $clean_tags = $this_tag;
                } else {
                    $clean_tags .= ',' . $this_tag;
                }
            }
        }
    }
    return $clean_tags;
}


A quiok breakdown,
- Divides the comma tags into an array.
- trim them to remove space prefix and suffix
- Removes duplicate entries.
- Returns a new comma delimated good $tag


3. Storing Tags


Simple SQL insert does this.


4. Parsing tags as repective URLs


Lemme add another function....

PHP Code
function generate_tag_links($tags, $base_link ){
    if(!empty($tags)) {
		$return = '';
		$tagsArray = array_map('trim', explode(',', $tags));
        foreach($tagsArray AS $tag) {
            $return .= "<a href=\"" . sprintf($base_link, urlencode($tag)) . "\">$tag</a> ";
        }
        return $return;
    }
    return false;
}

As you can see from the function it accepts two params, $tags (the tags as fetched from database). And $base_link.

The baselink must have a string placeholder "%s". Take for example i want my tags url to be my.website/tags/the_tag, the base_link will be 'my.website/tags/%s'. Also if i want my tag url to be my.website/tags.php?t=the_tag then i'll set 'my.website/tags.php?t=%s'.


5. Fetching articles of a particular tag


Thats simple, you easily use the "LIKE" SQL clause.


Example if i want articles tagged Ade360 my SQL query will be...

SQL Code
SELECT `title`, `author`, `tags`
FROM `articles`
WHERE `tags` LIKE '%Ade360%'"

.

I do hope you understand the gibberish stuff i just said above.

  • Date: Aug 05, 2016

I UnderStand But How To Insert The Codes Is The Problem.

Should I Drop My Forum Script Please

showtopic.php (7.5KB) [0 view]
  • Date: Aug 07, 2016

Like I said I've tried to explain everything you have to do.

It is not something you can do in just one script.

You just have to understand the technique and apply it.