Question2Answer Wordpress Entegrasyonu Nasıl Yapılır ? |
19 Mesajlar | 8.008 Okunma |
Gökhan Blog adlı üyeden alıntı
bu scriptin config dosyasına define('QA_WORDPRESS_INTEGRATE_PATH', '/PATH/TO/WORDPRESS');kaptanblack adlı üyeden alıntı
Entegrasyon sonrası ne gibi değişiklikler oluyor?function ago($time)
{
$periods = array("saniye", "dakika", "saat", "gün", "hafta", "ay", "yıl", "decade");
$lengths = array("60","60","24","7","4.35","12","10");
$now = time();
$difference = $now - $time;
$tense = "önce";
for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
$difference /= $lengths[$j];
}
$difference = round($difference);
return "$difference $periods[$j] $tense ";
}
/**
* @author Q2A Market
* @copyright 2013
* @Website http://www.q2amarket.com
* @version 1.00
*
*
* Description:
* ------------
* Get recent questions from Question2Anser website.
*
* Usage:
* ------
* Define Q2A path to $qa_path=site_root('YOUR_Q2A_PATH'); where 'YOUR_Q2A_PATH' is your q2a 'qa-config.php' file path.
*
* To list recent question you need to call 'qa_recent_questions($args=array())' function where you would like to dispaly.
* $args parameter can helps to customize html structure and css class.
*
* Parameters:
* -----------
* $args:-
* (array)(optional) Query string will override the values in $defaults.
* Default: None
*
* $limit:-
* (string)(optional) Must be an intiger value defined the number of question will be displayed.
* Default: 10
*
* $container:-
* (string)(optional) Valid HTML tag to wrap the un-order list of questions. Required only tag e.g 'div' and not '' no closing tag required.
* Default: None
*
* $container_class:-
* (string)(optional) CSS class for container
* Default: None
*
* $list_class:-
* (string)(optional) CSS class for UL un-order list
* Default: None
*
* Example:-
* ---------
* // set function parameter in array format
* $args = array(
* 'limit' => 25,
* 'container' => 'div',
* 'container_class' => 'recent-question',
* 'list_class' => 'q-list-item'
* );
*
* Now you can pass $args into the function
* qa_recent_questions($args);
*
* Note: This is a beta version and may or may not work with your website. Q2A Market is not responsible for any losses.
*
*
*/
//root path function
//Usually you do not have to touch this part.
function site_root($path=null){
$root = $_SERVER['DOCUMENT_ROOT'];
return $root.$path;
}
//recent question function.
// the function has everything include from databse to html output and can be modify as per your need.
// to use this function please refer above usage guide.
function qa_recent_questions(array $args = array()){
/*-----> define your questin&answer (qa) path (not url) <-------*/
$qa_path=site_root('/soru-sor/');
/*--------------------------------------------*/
$qa_directory = basename($qa_path);
require_once($qa_path.'qa-config.php');
include($qa_path.'qa-include/qa-base.php');
$prefix = constant('QA_MYSQL_TABLE_PREFIX');
$args += array(
'limit' => 10,
'container' => null,
'container_class' => null,
'list_class' => 'qa-list-item',
);
extract($args);
$list_class_item = 'class="'.$list_class.'"';
$ul = '';
$ulc = '
';
$query = qa_db_query_sub("
SELECT posts.*, UNIX_TIMESTAMP(posts.created) as creat, users.*, category.categoryid, category.title as cat_title
FROM ".$prefix."posts as posts
LEFT JOIN ".$prefix."users as users ON (posts.userid=users.userid)
LEFT JOIN ".$prefix."categories as category ON (posts.categoryid=category.categoryid)
WHERE posts.type= 'Q'
ORDER BY posts.postid DESC
LIMIT $limit
") or die(mysql_error());
echo $ul;
$i = 0;
while ($row = qa_db_read_one_assoc($query, true)):
$i++;
$title = $row['title'];
$alt_title = str_replace(array("'",'"'),array("",''),$row['title']);
$pid = $row['postid'];
$avatarblobid = $row['avatarblobid'];
$cat_title = $row['cat_title'];
if(!empty($avatarblobid))
$avatar_url = 'http://www.siteadresiniz.com/soru-sor/?qa=image&qa_blobid='.$avatarblobid.'&qa_size=40';
else
$avatar_url = 'http://www.siteadresiniz.com/noavatar.jpg';
if(strlen($title) > 25)
$title = mb_substr($title, 0, 25, 'UTF-8') . '...';
else
$title = $title;
$created = $row['creat'];
if($i==1)
echo '';
else
echo ' ';
echo ' '.$title.' '.ago($created).' '.$cat_title.'';
echo ' ';
endwhile;
echo $ulc;
}
?>
Kullanacağınız yere yapıştırın
$args = array(
'limit' => 8,
'container_class' => 'qa-recent-q',
);
qa_recent_questions($args);
?>
Fonksiyonu internetten bulmuştum fakat tasarımda daha önceden bu şekilde (avatar, x dakika önce, bölüm gibi ekstra bilgiler) olduğu için düzenleyerek kodu bu hale getirdim.
siteadresiniz ve soru-sor yazan yerleri değiştirmeyi unutmayın.
Örnek:
Wordpress: http://www.erkekgozuyle.com
Question2Answer: http://www.erkekgozuyle.com/soru-sor
kaptanblack adlı üyeden alıntı
function ago($time)
{
$periods = array("saniye", "dakika", "saat", "gün", "hafta", "ay", "yıl", "decade");
$lengths = array("60","60","24","7","4.35","12","10");
$now = time();
$difference = $now - $time;
$tense = "önce";
for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
$difference /= $lengths[$j];
}
$difference = round($difference);
return "$difference $periods[$j] $tense ";
}
/**
* @author Q2A Market
* @copyright 2013
* @Website http://www.q2amarket.com
* @version 1.00
*
*
* Description:
* ------------
* Get recent questions from Question2Anser website.
*
* Usage:
* ------
* Define Q2A path to $qa_path=site_root('YOUR_Q2A_PATH'); where 'YOUR_Q2A_PATH' is your q2a 'qa-config.php' file path.
*
* To list recent question you need to call 'qa_recent_questions($args=array())' function where you would like to dispaly.
* $args parameter can helps to customize html structure and css class.
*
* Parameters:
* -----------
* $args:-
* (array)(optional) Query string will override the values in $defaults.
* Default: None
*
* $limit:-
* (string)(optional) Must be an intiger value defined the number of question will be displayed.
* Default: 10
*
* $container:-
* (string)(optional) Valid HTML tag to wrap the un-order list of questions. Required only tag e.g 'div' and not '' no closing tag required.
* Default: None
*
* $container_class:-
* (string)(optional) CSS class for container
* Default: None
*
* $list_class:-
* (string)(optional) CSS class for UL un-order list
* Default: None
*
* Example:-
* ---------
* // set function parameter in array format
* $args = array(
* 'limit' => 25,
* 'container' => 'div',
* 'container_class' => 'recent-question',
* 'list_class' => 'q-list-item'
* );
*
* Now you can pass $args into the function
* qa_recent_questions($args);
*
* Note: This is a beta version and may or may not work with your website. Q2A Market is not responsible for any losses.
*
*
*/
//root path function
//Usually you do not have to touch this part.
function site_root($path=null){
$root = $_SERVER['DOCUMENT_ROOT'];
return $root.$path;
}
//recent question function.
// the function has everything include from databse to html output and can be modify as per your need.
// to use this function please refer above usage guide.
function qa_recent_questions(array $args = array()){
/*-----> define your questin&answer (qa) path (not url) <-------*/
$qa_path=site_root('/soru-sor/');
/*--------------------------------------------*/
$qa_directory = basename($qa_path);
require_once($qa_path.'qa-config.php');
include($qa_path.'qa-include/qa-base.php');
$prefix = constant('QA_MYSQL_TABLE_PREFIX');
$args += array(
'limit' => 10,
'container' => null,
'container_class' => null,
'list_class' => 'qa-list-item',
);
extract($args);
$list_class_item = 'class="'.$list_class.'"';
$ul = '';
$ulc = '
';
$query = qa_db_query_sub("
SELECT posts.*, UNIX_TIMESTAMP(posts.created) as creat, users.*, category.categoryid, category.title as cat_title
FROM ".$prefix."posts as posts
LEFT JOIN ".$prefix."users as users ON (posts.userid=users.userid)
LEFT JOIN ".$prefix."categories as category ON (posts.categoryid=category.categoryid)
WHERE posts.type= 'Q'
ORDER BY posts.postid DESC
LIMIT $limit
") or die(mysql_error());
echo $ul;
$i = 0;
while ($row = qa_db_read_one_assoc($query, true)):
$i++;
$title = $row['title'];
$alt_title = str_replace(array("'",'"'),array("",''),$row['title']);
$pid = $row['postid'];
$avatarblobid = $row['avatarblobid'];
$cat_title = $row['cat_title'];
if(!empty($avatarblobid))
$avatar_url = 'http://www.siteadresiniz.com/soru-sor/?qa=image&qa_blobid='.$avatarblobid.'&qa_size=40';
else
$avatar_url = 'http://www.siteadresiniz.com/noavatar.jpg';
if(strlen($title) > 25)
$title = mb_substr($title, 0, 25, 'UTF-8') . '...';
else
$title = $title;
$created = $row['creat'];
if($i==1)
echo '';
else
echo ' ';
echo ' '.$title.' '.ago($created).' '.$cat_title.'';
echo ' ';
endwhile;
echo $ulc;
}
?>
bu kodları nereye yapıştıracağız hocam ?