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

Note: This is for a core hack, no plugin.

I am searching the according PHP file that assigns the subnavigation to the user profile page, e.g. http://question2answer.org/qa/user/echteinfachtv+%28Kai%29

I would like to add "My Favorites" to the subnavigation list.

 

I have searched for $qa_content['navigation']['sub'] everywhere but could not find it for the user's page...

Found a couple of functions qa_account_sub_navigation(), qa_admin_sub_navigation(), qa_users_sub_navigation(), etc. but NO qa_user_sub_navigation().

Q2A version: 1.5.4
by
edited by
And why not maipulate the output through the advanced theme ?

To do the opposite, take one tab away, I did unset a element of $navigation=@$this->content['navigation'][$navtype]; inside the function nav($navtype, $level=null)

That worked. In Your case You could just check if You are on one of the usertemplates user, user-wall, user-questions, user-answers AND if the logged in user id matches with the user id of the profile page You are viewing AND if the ($navtype=='sub') . In that case You would add one more element to $navigation .

Edit: Since publishing Your tip hoo to have the user id accessible on profile page this became much easier, I still had to compare handles and paths,..... that was the reason why Your tip was such a great help ; )

2 Answers

+1 vote
by
edited by

Thanks again monk333, greeat tip!

This is what I have so far in the advanced theme, added it to existing override of function nav_main_sub():

function nav_main_sub() {
    $this->output('custom stuff');
    $this->nav('main');
    $this->nav('sub');

// add subnavigation 'favorites' to user page
if($this->template=='user') {
    $myhandle = basename( qa_path_html(qa_get_logged_in_handle()) );
    $myurl = strtok($_SERVER['REQUEST_URI'],'?');
    if($myurl == '/user/'.$myhandle){
        $this->content['navigation']['sub']['favorites'] = array(
                'label' => qa_lang_html('misc/nav_my_favorites'),
                'url' => qa_path_html('favorites'),
        );
    }
}

}

Actually it should add an element to the subnavigation but it does not :(

I printed out the associative array $this->content['navigation']['sub'] but the new element is not inside.

Could it be that the subnavigation is overwritten later and so my added element gets lost?

---

SOLVED:

Put the blue code block before   $this->nav('sub');  and it works!

---

+1 vote
by

See qa_user_sub_navigation(...) in qa-app-format.php

But you can be doing all of this via a layer or advanced theme.

by
That's working, thanks! So instead of overriding function nav_main_sub() we have to override function doctype().
@gidgreen: Why?

@Onurb: Outstanding design, like it :)
by
Ah! I can also add this element to the subnavigation. I have to add the code block above in my answer (blue colored) BEFORE $this->nav('sub');

Then it appears!
by
Oh yes that's probably smarter :D thanks for the compliment!
by
Hi q2apro! i tried the code you suggested above and did not work... i am using V1.6.2 is there any updates that i shoul dtake into consideration ? thank you !
...