Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
in Q2A Core by
For example, $title is a global variable to display the pages title.

 I'm modifying the page_title function (putting a if/else statement in place) that if the page template == "question" to make a few changes.  One of these changes is to display the category that the current question the user is viewing is in.

Is there a global/accessible variable such as $category that I can call?

Anyone know how I can grab what CATEGORY the current question a visitor is looking at?  (and then display this category name on the current page?)

I'm editing the section($title) function in qa-theme.php

1 Answer

0 votes
This I as well do not know, but if You see the function

function post_meta($post, $class, $prefix=null)

there is generated the schema: asked 3 days ago in musik by jimmy

what, when, where, who

i believe this part:

    case 'where':
                        $this->output_split(@$post['where'], $class.'-where');

should point You in the right direction. I have very limited programming skills, hope in Your case it is better and You find the way...

regards monk
Thanks for the suggestion monk, but still a little stuck.  Maybe if I re-ask what I'm trying to do, someone else will have a suggestions.  (Ultimately, maybe we should make a wiki or info page on how to modify the default theme, call functions, what variables are, etc...)

My question,

In qa-theme.php I've modified the page_title function so that when the template == question, the "section header" of the page says "Category Question" above the actual question that was asked.  I would like to substitute the word Category with the actual Category where the question was asked in.

I'm new, but quickly learning and adapting to PHP.  The page_title function only calls $title, so I'm wondering how do I capture/call the category the visitor is currently looking at?
As I told before, I am in the same situation of limited php knowledge.

The function I mentioned above You can add to Your advanced theme, see instructions, and then play around with it to sse if You can get it to work in some way. I hope You already have build Your advanced theme, in my one I added a huge part of the functions and play around there.

The "where" part of this function at least includes the category already.

May be one of the more experienced users could help on this. Gidgreen himself actually is working on the new version, so I think he wont have to much time actually.

In a few days I have more time again, and will as well try to figure it out, but cant promise that I will resolve it by myselfe.

With some help from Gidgreen and a lot of patience, I figured it out!

On the questions page, the value of what category you're actually looking at (w/ URL) is stored in an array.

To access this info/grab the full URL with Anchor text, you want to add the following PHP code to a function in the qa-theme.php file.  (In my case, I'm editing the page_title($title) function.

echo $variableName

Give that a shot!  If you want to modify what is being displayed, you can use the str_replace function on the $variableName.

By default, that echo statement will print:

<A HREF="../url_to_category" CLASS="qa-category-link">Category Name</A>

If you wanted to change this link of text (for example the class of this link), you could do:


This code will swap out "qa-category-link" and replace it with "qa-category-link-NEW"

Let me know if you find this useful.