Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+7 votes
in Q2A Core by
I wolud like to exclude one category from being shown on my home page, but it to exist and anyone to be able to see its content when he/she goes to the category.

Is this possible and how?

Thank in advance!

2 Answers

+3 votes
edited by

Copying and pasting my answer from http://www.question2answer.org/qa/14058/exclude-category-in-questions-list

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) {
$urlPart= explode('/', $_SERVER['REQUEST_URI_PATH']);

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. 

And lastly, 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. 

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.

Please, bobbyscon give complete example. I did first part correctly and was able to hide questions from category which I want. But even I go to that category, there's no any questions. The reason is I couldn't understand second url slug part.
In your example what we have to write in "enhancement-request" please don't explain, just give an example
+1 vote

In Q2A v1.8.3, the category ID needs to be included in the WHERE clause of the SQL query here and here such that questions in that category can be excluded. For more information please check this similar question.