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

1 Answer

+1 vote
by
selected by
 
Best answer

It's possible to hide questions from a given category by augmenting the
signature of qa_db_qs_selectspec() and qa_db_recent_a_qs_selectspec() and
including the category ID of such category as a function parameter. These functions can't be overridden so in the new version of these, say qa_db_qs_new_selectspec() and qa_db_recent_a_qs_new_selectspect() respectively, 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.

An override is also needed to replace this:

list($questions1, $questions2, $categories, $categoryid, $custompage) = qa_db_select_with_pending(
	qa_db_qs_selectspec($userid, 'created', 0, $slugs, null, false, false, qa_opt_if_loaded('page_size_activity')),
	qa_db_recent_a_qs_selectspec($userid, 0, $slugs),
	qa_db_category_nav_selectspec($slugs, false, false, true),
	$countslugs ? qa_db_slugs_to_category_id_selectspec($slugs) : null,
	($countslugs == 1 && !$explicitqa) ? qa_db_page_full_selectspec($slugs[0], false) : null
);

with this:

$categoryid = qa_db_select_with_pending($countslugs ? qa_db_slugs_to_category_id_selectspec($slugs) : null);

if (isset($categoryid) || ($countslugs == 1 && !$explicitqa)) {
	// Keep standard listing since it's either a category page or a custom page
	list($questions1, $questions2) = qa_db_select_with_pending(
		qa_db_qs_selectspec($userid, 'created', 0, $slugs, null, false, false, qa_opt_if_loaded('page_size_activity')),
		qa_db_recent_a_qs_selectspec($userid, 0, $slugs)
	);
} else {
	// Exclude this category ID in homepage
	$ignored_category_id = 123;

	list($questions1, $questions2) = qa_db_select_with_pending(
		qa_db_qs_new_selectspec($userid, 'created', 0, $slugs, null, false, false, qa_opt_if_loaded('page_size_activity'), $ignored_category_id),
		qa_db_recent_a_qs_new_selectspec($userid, 0, $slugs, null, false, false, null, $ignored_category_id)
	);
}

list($categories, $custompage) = qa_db_select_with_pending(
	qa_db_category_nav_selectspec($slugs, false, false, true),
	($countslugs == 1 && !$explicitqa) ? qa_db_page_full_selectspec($slugs[0], false) : null
);

in qa-include/pages/default.php:51

...