Welcome to the Question2Answer Q&A. There's also a
demo
if you just want to try it out.
Login
Login
Register
All Activity
Questions
Hot!
Unanswered
Tags
Users
Ask a Question
About
Wiki
Welcome to the Q&A for
Question2Answer
.
If you have questions about the platform,
click here to ask
and please use English.
If you just want to try Q2A, please use the
demo
, which also grants admin access.
Apr 29:
Q2A 1.5.2
Related questions
Want to pay upto $150 if you can show me how to import wordpress data to Q2A site!
Tag cloud broken
Tag cloud caching?
Additional request of tag cloud plug-in
Quick suggestion for tag cloud...
How do I make the Category filter affect the tag cloud?
Tag Cloud only showing 5 words
Logarithmic Tag Cloud Plugin, Anyone?
any one tried to integrate with wordpress?
embedding in to wordpress theme - no login merge, only visual
All categories
Q2A Core
(3,262)
Plugins
(358)
Can one merge Q2A tag cloud with wordpress site tag cloud
0
votes
Is there a way where I can push my tag data of Q2A website to my wordpress section (both on same domain)
tag-cloud
wordpress
asked
Oct 24, 2011
in
Q2A Core
by
mbabug
Please
log in
or
register
to add a comment.
Please
log in
or
register
to answer this question.
1 Answer
+2
votes
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;
?>
answered
Oct 24, 2011
by
NoahY
Please
log in
or
register
to add a comment.