glepiza
asked on
how should I use wordpress conditionals ?
Dear experts,
I am having some issues adding a text below a page header of my custom taxonomies template. For example I have the following custom taxonomy template: taxonomy-dirtax-games.php following wordpress docs such as taxonomy-{taxonomy}-{term} .php. I am trying to add a text below the header with the next code:
function stufftodo_nav_menu() {
if (has_term( 'games', 'dirtax' ) ){
echo '<div class="side-nav-text">GAME S</div>';
}
};
add_action('genesis_after_ header', 'stufftodo_nav_menu', 5);
For some reason it does not display the text unless I have post under that taxonomy. For example If I go to the Games page and there is nothing in there, the text Games won´t be displayed unless I add a post.
Could you please help me to solve that, I am not sure if it has to do with the way I am using the conditional
Thanks
I am having some issues adding a text below a page header of my custom taxonomies template. For example I have the following custom taxonomy template: taxonomy-dirtax-games.php following wordpress docs such as taxonomy-{taxonomy}-{term}
function stufftodo_nav_menu() {
if (has_term( 'games', 'dirtax' ) ){
echo '<div class="side-nav-text">GAME
}
};
add_action('genesis_after_
For some reason it does not display the text unless I have post under that taxonomy. For example If I go to the Games page and there is nothing in there, the text Games won´t be displayed unless I add a post.
Could you please help me to solve that, I am not sure if it has to do with the way I am using the conditional
Thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I mean, I am not writing the condition, only:
function stufftodo_nav_menu() {
echo '<div class="side-nav-text">GAME S</div>';
};
add_action('genesis_after_ header', 'stufftodo_nav_menu', 5);
function stufftodo_nav_menu() {
echo '<div class="side-nav-text">GAME
};
add_action('genesis_after_
ASKER
hmm, never mind, i need to display that word game in other templates as well. So am back to the beginning.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hello Tom,
thank you very much for being willing to answer my wordpress question, I appreciate it.
I did what you suggested me to add the code directly into the template, that worked but when I was having issues on single post pages. So I ended up doing this:
if (in_array('term-stay',$cla sses) || (pa_in_taxonomy('directory tax', 'stay')&& (is_single()))) {
?>
<div class='section-title'><spa n>GAMES</s pan></div>
<?php
}
So, first I was checking if the class term-stay was on the template, then I checked if the post belonged to a custom taxonomy following this tutorial :http://cazue.com/articles/wordpress-check-if-post-belongs-to-custom-taxonomy-2013
and also I checked if it was a single post.
I know this question was difficult because there were many things going on in here. But thank you for answered me because your last input led me to find the answer
Thanks!!!!
Winter
thank you very much for being willing to answer my wordpress question, I appreciate it.
I did what you suggested me to add the code directly into the template, that worked but when I was having issues on single post pages. So I ended up doing this:
if (in_array('term-stay',$cla
?>
<div class='section-title'><spa
<?php
}
So, first I was checking if the class term-stay was on the template, then I checked if the post belonged to a custom taxonomy following this tutorial :http://cazue.com/articles/wordpress-check-if-post-belongs-to-custom-taxonomy-2013
and also I checked if it was a single post.
I know this question was difficult because there were many things going on in here. But thank you for answered me because your last input led me to find the answer
Thanks!!!!
Winter
You're welcome, glad I could be of some assistance. Thanks for the points.
ASKER
I found the answer. But Tom did helped me to think about what I was doing wrong. Thanks!
ASKER
One question, I was adding that function inside function.php, but now I am adding it inside axonomy-dirtax-games.php and it seems to be working. Is that ok? Sometimes I don´t know what should go into functions.php or page templates etc...