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

I need to add new links to the nav sub list. For example in the questions page there exists these links:

how can I add another link to this list?

thanks. 

1 Answer

+1 vote
by
selected by
 
Best answer

Adding a link is the easy part. The complex part is adding some logic into it :)

Anyway, to add a link just create a layer and add this method to it:

public function initialize(){
    if ($this->template === 'questions') {
        $newSort = 'new-sort';
        $newTabSelected = qa_get('sort') === $newSort;
        $this->content['navigation']['sub']['recent']['selected'] = $this->content['navigation']['sub']['recent']['selected'] && !$newTabSelected;
        $this->content['navigation']['sub']['my-id'] = array(
            'label' => 'Link text',
            'url' => qa_path_html('questions', array('sort' => $newSort)),
            'selected' => $newTabSelected,
        );
    }
    parent::initialize();
}

Piece of cake!

by
Thank you pupi. What if template is a custom page?
by
Rather than answering the question directly, I'll let you figure out how to answer it. Just echo the template (right above the IF statement) while you're browsing the page and you'll find out what the name is.

echo $this->template;
by
Thank you for your answer.
I have two custom pages(I created them from admin/pages/add page) the slug of one of them is "help" and the other "ads". after  "echo $this->template;" I found out the name of the both is "custom". I want to add links to the sub nav of the help page. is it possible?
by
Got it. In this case you could use qa_request() then.
...