Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
1.8k views
in Q2A Core by
Q2A version: 1.8

1 Answer

+2 votes
by
edited by

You'll have to hack the core.

1. Edit file db/selects.php

2. Change this part of the code in function qa_db_qs_selectspec:

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

$selectspec['source'].=" JOIN (SELECT postid FROM ^posts WHERE ".

into this

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

$hiddenCategoryIds = array(1, 2);
$hideInPages = array('', 'activity', 'questions');
if (in_array(qa_request(), $hideInPages) && !empty($hiddenCategoryIds)) {
    $sql = '(^posts.categoryid NOT IN (' . implode(',', $hiddenCategoryIds) . ') OR ^posts.categoryid IS NULL) AND ';
} else {
    $sql = '';
}
$selectspec['source'] .= " JOIN (SELECT postid FROM ^posts WHERE " .
            $sql.

You can get the category IDs from the admin panel in the categories section. Navigate to the category you want to hide and then check the URL. It should look like this:

http://yoursite.com/admin/categories?edit=7

So 7 is the category ID. Make sure you replace the content of the array with that ID:

$hiddenCategoryIds = array(7);

The $hideInPages array controls in which pages you want to hide them. If you don't want t see them in any additional page, then uncomment (remove the // from the echo qa_request();) and navigate to that page. You will most likely text in the top left corner of the page. Just add that text to the $hideInPages array. Then comment the uncommented line again.

Note about the /activity page: 

You will see the core has also these functions:

    qa_db_recent_a_qs_selectspec()
    qa_db_recent_c_qs_selectspec()
    qa_db_recent_edit_qs_selectspec()

You'll have to perform similar edits to those functions in order to filter out all the questions (asked, answered, commented and edited). This answer just tackles the "asked" ones but fixing the rest should be trivial based on how the "asked" ones are fixed.

This is very very dirty and I wouldn't advise to hack the core that much... but it should get the work done.

by
@pupi1985, Thanks again!
I will give a try..
by
Perfect!!! Worked for me... :D
by
qa_db_posts_basic_selectspec function can be overridden but not qa_db_qs_selectspec. Otherwise corehack could have been avoided.
by
Seems there is a bug. After applying this hack, question list li broken on click of a category.

Could you please suggest me how to proceed...
by
I don't see it broken. Are you 200% sure if you remove this hack the list looks good? I'm assuming you have the "echo" commented, right?

As a side note, I've realized there are some conditions that might not make the questions hidden in the activity list which will require to make more changes to other functions. Not suitable to fit an answer here but rather as a feature request
by
@pupi1985, I was out on holiday. Apologies for late response.
Yes, It started working perfect after I did undo.
by
It is extremely unlikely that filtering out some results in that query would result in broken HTML, which I happen not be able to reproduce locally. Not much I can do. However, you can install Q2A from scratch on a test server, apply the changes and you will most likely see it doesn't generate that error. If it does, then you will have the step by step instructions to reproduce this which is what I need :)
by
@pupi1985, OOps, I didn't meant broken html!
After applying fix, the categories were showing different questions(In the ways, question list in categories was broken).  I should have been more explicit.
by
I see now. The issue was I told to delete up to (including) the line with the: qa_db_categoryslugs_sql_args. That was a copy/paste issue and should have not been included to be replaced. So the addition should work, just don't remove that last line (I've updated the answer anyway).

Also see the note about the /activity page.

Finally, remember to add each of the pages you want these "exceptions" to be run (e.g.: if you want to hide questions under a given category then you have to add the output of the qa_request() in the $hideInPages array).
by
Hello Friend!

The code above asks the questions asked in a category to disappear from the homepage, but when the question is answered it appears again on the homepage. How do I resolve so that when the question is answered or commented, it does not appear on the homepage?

Sorry, I'm using a translator.
by
Please, re-read the answer. That was already part of the answer
by
Thanks a lot for the help!

I just can not understand exactly what I have to edit in the functions:

qa_db_recent_a_qs_selectspec ()
qa_db_recent_c_qs_selectspec ()
qa_db_recent_edit_qs_selectspec ()
...