Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+3 votes
811 views
in Q2A Core by
edited by
Is there anyone knows HOW to change home page question list by random not by Time
The reason why i want this is :I want make the spider find new links when there is no new post
Thanks
by
I also need this
by
The reason why i want this is :I want make the spider find new links when there is no new post
Thanks

1 Answer

0 votes
by
edited by

I modify two file to make this requirement works, but i do not think it is the best way to do this , hope someone can give a better way to support this feature

welcome to my website  http://ostack.cn/  to see example page

1.“qa-include\db\selects.php" , change function qa_db_qs_selectspec from order by to rand

The modify de code as below:

function qa_db_qs_selectspec($voteuserid, $sort, $start, $categoryslugs = null, $createip = null, $specialtype = false, $full = false, $count = null)

{

if ($specialtype == 'Q' || $specialtype == 'Q_QUEUED') {

$type = $specialtype;

} else {

$type = $specialtype ? 'Q_HIDDEN' : 'Q'; // for backwards compatibility

}

$count = isset($count) ? min($count, QA_DB_RETRIEVE_QS_AS) : QA_DB_RETRIEVE_QS_AS;

switch ($sort) {

case 'acount':

case 'flagcount':

case 'netvotes':

 case 'views':

$sortsql = 'ORDER BY ^posts.' . $sort . ' DESC, ^posts.created DESC';

break;

case 'created':

case 'hotness':

//$sortsql = 'ORDER BY ^posts.' . $sort . ' DESC'; //before modify 

$sortsql = 'and  ^posts.postid >= (SELECT floor( RAND() * ((SELECT MAX(^posts.postid) FROM ^posts)-(SELECT MIN(^posts.postid) FROM ^posts)) + (SELECT MIN(^posts.postid) FROM ^posts)))';//after modify

break;

default:

qa_fatal_error('qa_db_qs_selectspec() called with illegal sort value');

break;

}

$selectspec = qa_db_posts_basic_selectspec($voteuserid, $full);

$selectspec['source'] .=

" JOIN (SELECT postid FROM ^posts WHERE " .

qa_db_categoryslugs_sql_args($categoryslugs, $selectspec['arguments']) .

(isset($createip) ? "createip=UNHEX($) AND " : "") .

"type=$ " . $sortsql . " LIMIT #,#) y ON ^posts.postid=y.postid";

if (isset($createip)) {

$selectspec['arguments'][] = bin2hex(@inet_pton($createip));

}

array_push($selectspec['arguments'], $type, $start, $count);

$selectspec['sortdesc'] = $sort;

return $selectspec;

2.Change  'qa-include\app\page.php' , change  the home page from 'pages/default.php' to  'pages/question.php'

function qa_get_request_content()

{

if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }

$requestlower = strtolower(qa_request());

$requestparts = qa_request_parts();

$firstlower = strtolower($requestparts[0]);

$routing = qa_page_routing();

    if(empty($requestlower)){

qa_set_template('questions');

$qa_content = require QA_INCLUDE_DIR . 'pages/questions.php'; 

} elseif(isset($routing[$requestlower])) {

qa_set_template($firstlower);

$qa_content = require QA_INCLUDE_DIR . $routing[$requestlower];

} elseif (isset($routing[$firstlower . '/'])) {

qa_set_template($firstlower);

$qa_content = require QA_INCLUDE_DIR . $routing[$firstlower . '/'];

} elseif (is_numeric($requestparts[0])) {

qa_set_template('question');

$qa_content = require QA_INCLUDE_DIR . 'pages/question.php';

} else {

qa_set_template(strlen($firstlower) ? $firstlower : 'qa'); // will be changed later

$qa_content = require QA_INCLUDE_DIR . 'pages/default.php'; // handles many other pages, including custom pages and page modules

}

if ($firstlower == 'admin') {

$_COOKIE['qa_admin_last'] = $requestlower; // for navigation tab now...

setcookie('qa_admin_last', $_COOKIE['qa_admin_last'], 0, '/', QA_COOKIE_DOMAIN, (bool)ini_get('session.cookie_secure'), true); // ...and in future

}

if (isset($qa_content))

qa_set_form_security_key();

return $qa_content;

}

by
Thanks. I have implemented this and it works.. but why do you think its not the best way?
by
As this has changed the basic file , this will influence the frame, and it may import some issues.
for example: 1.the paging for the question does not work well,if you select the last page it show nothing  (I know the reason but i do not want to change it );2. as we change the default.php , the costum home page will not work.

And i think the best way do this is :add an opertion in admin which can be select or provide a plugin to do this
by
It also create problem while uploading images
by
reshown by
can you give me more details?
I think this change has nothing to do with post and uploading images
by
No... when I am changing to this code. Then it is giving error in uploading images in ask page and answer in question page. And when I have restored default code then images uploading successfully.
by
I update page.php in the answer ,add new judge for home page,and test upload images works,you can have a try.
beside ,also chage selecet.php ,move 'case views:' to the origianl

if(empty($requestlower)){

qa_set_template('questions');

$qa_content = require QA_INCLUDE_DIR . 'pages/questions.php';

}
by
I think I should not disturb the core. It definitely need a different plugin
by
I will try to do this with a plugin , but before that i need to understand the QA framework clearly . It may use some times, that is why i said 'hope some one give a better way'
by
You can do the similar change for activity page - not questions page - because activity page is not paginated and is just "50" questions max. So, random is fine here.

If this has to be a plugin, then the activity page must be redirected to a custom page calling all the above db functions - mostly copy paste work. Then an admin option to switch between "Recent questions" and "Random questions".
by
how to do this on qa page ?
by
Is there any other query for random ?
like this  
$random_question = qa_db_read_one_assoc( qa_db_query_sub('SELECT * FROM ^posts WHERE type=$ ORDER BY rand() LIMIT 1', 'Q'), true );
...