Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+7 votes
9.6k views
in Q2A Core by
edited by
In what file should I need to have a look in order to do that?

I just want to exclude questions of a specific category in the Questions list.

However, I do want them to show up in All Activity...

It's pretty vital for my website, I'm hoping someone can just give me the right directions, I will try to solve it by myself.
Q2A version: 1.5.1
by
edited by

Here is similar question that works in Q2A v1.8.3 in homepage, but the procedure is similar for other pages too.

2 Answers

+4 votes
by

I managed to do this partly by going to $q_item function in qa-theme.php.

I replaced this

foreach ($q_list['qs'] as $q_item)
$this->q_list_item($q_item);

by:

foreach ($q_list['qs'] as $q_item)
if($q_item['raw']['categoryid'] != 21){
    $this->q_list_item($q_item);
}

This removes all questions from the list, with categoryID 21.

However...  this tweak also causes the question list to be smaller in size.

If for example the questions list has 10 questions, with 3 of them from cat ID 21, then using this tweak leaves me alone with 7 questions in the list...

I still would like to see 10 questions though, however, not from the cat ID 21...

Can anyone help me out?

by
Having the same issue. Technically once exclude the category it should completely ignore like doesn't exists but it seems hiding but leaving footprints there. I am also trying to solve this issue. If you get solution please let me know.
by
Any solution to this problem  ?
by
I know this is an old question, but on ver 1.6.3 this function doesn't appear in qa-theme.php. Can you elaborate on if this was a function you added or if there's somewhere else to modify this code now?
0 votes
by
edited by

This is what I ended up with, in case it helps:

In the qa-theme-base.php file in the qa-include folder, I modified the q_list_items function. Sorry about the formatting, I'm not sure how to format code on a Q2A site. Items in green are what you'll need to customize for your own needs.

function q_list_items($q_items)

{
foreach ($q_items as $q_item){
if($q_item['raw']['categoryid'] != 8) {
$this->q_list_item($q_item);
}
$_SERVER['REQUEST_URI_PATH'] = parse_url($_SERVER['REQUEST_URI'],PHP_URL_PATH);
$urlPart= explode('/', $_SERVER['REQUEST_URI_PATH']);
 
if($urlPart[1]=="enhancement-request")
$this->q_list_item($q_item);
 
if(array_key_exists(2,$urlPart)){
if($urlPart[2]=="enhancement-request")
$this->q_list_item($q_item);
}
 
if(preg_match('/search/', $urlpart[1]))
$this->q_list_item($q_item);
 
if($urlpart[1]=="user")
$this->q_list_item($q_item);
}
}

So here's a quick summary of what's happening:

In the first section, we're telling the query to determine if the category id # is not 8 and if it is NOT 8, then show the question. If it is 8, then don't do anything. You'll need to change this to match the category id that you need. Easiest way to get that id is to go to Admin --> Categories then click on the category name. Because that name is a URL, you'll see the end of the URL ends like "/admin/categories?edit=8". You'll also need the slug, or URL fragment, for the second part of this function.

After that section of code, we do a query of the server to retreive the possible URL segment outcomes. Simply put, a URL segment is what's between the / marks. So with the example www.question2answer.org/questions/category, www.question.org is segment 0, questions is segment 1, and category is segment 2. 

Next, in order to show those questions when you navigate to the category page either from the home page or from the questions page (so www.question2answer.org/category or www.question2answer.org/questions/category), we need to query the segment of the URL you're currently on. The first query looks for your category slug to be in segment 1, and the second query determines first if a segment 2 exists (to prevent a php notice from appearing on your site) and then if your category slug is in segment 2. 

Lastly, I wanted to make sure questions in that category turn up in searches and also in each user's acitivity when viewing their profiles. The last 2 if statements take care of those.

I am very new to php with my experience lying in .NET and objective-c, so if someone thinks this needs improvement, please let me know.

by
Side note: this does not fix the issue addressed in the first answer with the number of questions appearing. I've set my limits to 20, so it doesn't bother me too much, but I'll see if I can tweak the code to not count those questions towards the limit.
by
Did you get a solution for the question count Bobby?
by
it cannot work on verson 1.7
...