Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Override main() function to display question view page content only for looged in user for defined category. If condition fails than we will throw error message and provide login link to user for better usability.
* Q2A Market Block Category Content for Loggedin user
* @author Q2A Market
* @category Hook
* @Version: 1.00
* @author URL:
* @Q2A Version 1.6+
* Usage: Chnage the first child with yoru cateogry
function main()
* for better understanding what $content holds
* Do:
* echo '<pre>', print_r($content), '</pre>';
* or
* echo '<pre>', var_dump($content), '</pre>';
$this->output('<div class="qa-main'.(@$this->content['hidden'] ? ' qa-main-hidden' : '').'">');
// set condition to set categoryname/categoryid
// also check if user logged in or not
if((@$content['q_view']['raw']['categoryname'] !== 'The first child') || qa_is_logged_in()) {
$this->widgets('main', 'top');
$this->widgets('main', 'high');
/*if (isset($content['main_form_tags']))
$this->output('<form '.$content['main_form_tags'].'>');*/
/*if (isset($content['main_form_tags']))
$this->widgets('main', 'low');
$this->widgets('main', 'bottom');
} else {
// throw error message if condition fails
// also provide login url for usability
$this->output('<div class="qa-error">Please <a href="'.qa_opt('site_url').'?qa=login">Login</a> to view content</div>');
} // end condition here
$this->output('</div> <!-- END qa-main -->', '');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment