Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
488 views
in Q2A Core by
Is there a way where I can push my tag data of Q2A website to my wordpress section (both on same domain)

1 Answer

+2 votes
by
I used a php widget plugin to accomplish this (mostly just copied the code from the log-tag plugin); it won't work on the wordpress blog itself - you'll need more includes for that, but it works in the case of wrapping Q2A in the Wordpress theme:

<?php
            function FromParetoCurve($weights, $minSize, $maxSize)
            {

                $logweights = array(); // array of log value of counts
                $output = array(); // output array of linearized count values

                 // Convert each weight to its log value.
                foreach ($weights AS $tagname => $w)
                {
                    // take each weight from input, convert to log, put into new array called logweights
                    $logweights[$tagname] = log($w);
                }

                 // MAX AND MIN OF logweights ARRAY
                $max = max(array_values($logweights));
                $min = min(array_values($logweights));

                foreach($logweights AS $lw)
                {     
                    if($lw < $min) {
                        $min = $lw;
                    }
                    if($lw > $max)
                    {
                        $max = $lw;
                    }
                }

                // Now calculate the slope of a straight line, from min to max.
                if($max > $min)
                {
                     $slope = ($maxSize - $minSize) / ($max - $min);
                }

                $middle = ($minSize + $maxSize) / 2;

                foreach($logweights AS $tagname => $w)
                {
                    if($max <= $min)           {     
                        //With max=min all tags have the same weight.     
                        $output[$tagname] = $middle;    
                    }    
                    else    {     
                        // Calculate the distance from the minimum for this weight.     
                        $distance = $w - $min;
                        //Calculate the position on the slope for this distance.
                        $result = $slope * $distance + $minSize;
                        // If the tag turned out too small, set minSize.
                        if( $result < $minSize) {
                            $result = $minSize;     
                        }     //If the tag turned out too big, set maxSize.
                        if( $result > $maxSize)
                        {
                            $result = $maxSize;
                        }
                        $output[$tagname] = $result;
                    }
                }
                return $output;
            }
            
            require_once QA_INCLUDE_DIR.'qa-db-selects.php';
            
            $populartags=qa_db_single_select(qa_db_popular_tags_selectspec(0, (int)qa_opt('log_tag_cloud_count_tags')));
            
            $maxsize=(int)qa_opt('log_tag_cloud_font_size');
            $minsize=(int)qa_opt('log_tag_cloud_min_font_size');        

            $scale=qa_opt('log_tag_cloud_size_popular');
            
            if($scale) {    
                // convert from linear to log
                
                $populartags = FromParetoCurve($populartags, $minsize, $maxsize);
            }    
                    
            if(qa_opt('log_tag_cloud_sort_type') == 'alphabetical') {
                
                // sort alphabetical
                
                ksort($populartags);
            }

            $output .='<DIV STYLE="font-size:10px;">';
            
            foreach ($populartags as $tag => $count) {
                
                $size=number_format(($scale ? $count : $maxsize), 1);
                
                $output .='<A HREF="'.qa_path_html('tag/'.$tag).'" STYLE="font-size:'.$size.'px; vertical-align:baseline;">'.qa_html($tag).'</A> ';
            }
            
            $output .='</DIV>';
            echo $output;

?>
...