I’m trying to make my custom sidebar.php file for wordpress aware of what page it is beeing loaded on. You see, I want to add "sub links" when you click a category link so to speak. At this time the sidebar is made with normal links like this:
I might be misunderstanding your question, it sounds like a job for Conditional statements, however….
You can easily manage this with widgets!
I use flexipages to set the parent / child links, you can have multiple instances of flexipage if you have more than one set of subpages. Then I use TS custom Widgets to control which widgets appear on which pages / posts / categories / archives etc. using conditional statements.
For me this was great because it eliminated the need to create custom templates calling custom sidebars etc. I found that to get messy in a hurry and difficult to manage changes.
And it works well, if the page is a subpage, or has subpages then they get displayed. This can be changed how ever someone else wants to use it. But it’s worked well on a couple of wordpress sites now.