Greetings, I would like to echo some lines of text depending on the category name on Wordpress, but it could be at any other php script. single_cat_title() is a function that returns the name of the current category. If I make it will print house, for example. What I would like is to output the following line in the footer: "You can find houses at...", if category name is house. It could be used as small context related ads or quotes. But I tried many things and nothing worked. Even if I pass the result of the function to a variable, before using it in the switch command, it still isn't working. I must be doing something wrong. Anyone thought about it? It would be a nice way of having semi-contextual ads.
Perhaps something extra is getting outputted so that it'll never match? (line break or such). Try and copy only the first 5 positions of the output when it is "house" to a variable and switch on that, just to make sure.
I'd put in a temporary debug there <?php var_debug(single_cat_title()); ?> Code (markup): and see what's being spat out.
Thank you for your help. I will try both tips. It's really printing just the word house, so it may be any invisible element like blinxdk said. Thank you again
We should never do coding at high hours of the night... I just noticed that <?php echo single_cat_title(); ?> isn't outputting anything outside the category archive, so it's obvious this could never work on a single page as I was testing... Well, it was worth the try. I've read lots of topics: Page templates http://codex.wordpress.org/Pages#Page_Templates Category templates http://codex.wordpress.org/Category_Templates The Loop http://codex.wordpress.org/The_Loop http://codex.wordpress.org/Template_Tags/category_description http://codex.wordpress.org/Template_Tags/get_the_category But I'm not seeing how I can do this to work on single pages. It would have to call the category name correctly, and then output the correct sentence. This is easy to do in categories archives, but a little more difficult in single pages. I just start messing with Wordpress, and I still don't know the best functions to call.