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

I need to add an onclick into the <a href... of one of the navigation elements. I do not intend to use jquery this time.

How can I write the code into the menu nav element?

What can be declared is (this I found in qa-app-format.php):

                'url' =>
                'label' =>
                'opposite' =>
                'target' =>
                'selected' =>
 

Where do I put the onclick?

1 Answer

+1 vote
by

Add this to your theme override:

function html()    {

$this->content['navigation']['your-menu-type']['your-nav-item']['onclick']= 'javascript:yourjavscript';

qa_html_theme_base::html();

}

 

you can also do a foreach loop if you want to replace multiple items

by
Thanks for your answer Aryan! I am changing the nav order in page.php (core), and need to add the content there. However, your approach seems not to give me the onclick. I am using now:

            $qa_content['navigation']['main']['tag']=array(
                'url' => 'http://mycustomlink.com/',// qa_path_html('tags'),
                'label' => 'my custom link', //qa_lang_html('main/nav_tags'),
                'target' => 'blank',
                'onclick' => 'console.log("test")',
            );

onclick does not appear. Any idea?
by
first thing dont modify core files, As I did many customization without touching a single core file. you can change everything from theme itself.
first tell me why you are doing this.. and then I will post the code..
by
r u using  $qa_content ? if yes then did u set global  $qa_content  inside function. Show me the full function
by
I know that for the purpose of updates core files should not be touched.... but there were so many core hacks necessary, that were not going to be solved by advanced themes or plugins, see my list here: http://www.question2answer.org/qa/16488/

For the issue above, you find the code in page.php, about line 542 after: if (qa_using_tags() && qa_opt('nav_tags'))
...