poindexter Posted April 8, 2010 Share Posted April 8, 2010 Hi, My goal is to display a certain set of information in my sidebar when a particular category is being viewed. I'm using Wordpress. I've tried a number of different solutions (like creating a different sidebar file and calling it as an include on the particular category template page instead of using the get_sidebar function as well as trying my hand at a conditional test within the sidebar.php file) and have come up short. I'm not a php expert by any means and I imagine that there may be something rather simple here that I've missed. Here's the existing sidebar.php file: <div class="sidebar"> <?php if (!is_search() && !is_page('Our Clients') && !is_archive()){ if($post->post_parent) { $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0&depth=1&exclude=85,87,89,181,97,184"); } else { $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0&depth=1&exclude=85,87,89,181,97,184"); } if ($children) { ?> <div class="panel links subnav"> <h3>In This Section</h3> <ul class="subnav"> <?php echo $children; ?> </ul> <p> </p> </div> <?php } } if(is_page('Our Clients') || in_category('Our Clients') || is_category('Our Clients')) { echo '<div class="panel links subnav">'; echo '<h3>In This Section</h3>'; echo '<ul class="subnav">'; wp_list_categories('child_of=21&title_li='); echo '</ul>'; echo '<p> </p>'; echo '</div>'; } if (!is_page('Resources')){ ?> <div class="panel featured-resource"> <h4>Featured Resource</h4> <div class="embed"> <?php $custom_fields = get_post_custom(); $featured_video_code = $custom_fields['Featured Video Code']; if($featured_video_code) { foreach ( $featured_video_code as $key => $value ) { $the_code = $value; } $featured_video_link = $custom_fields['Featured Video Link']; foreach ( $featured_video_link as $key => $value ) { $the_link = $value; } $featured_video_text = $custom_fields['Featured Video Text']; foreach ( $featured_video_text as $key => $value ) { $the_text = $value; } if($the_code) { echo $the_code; } if($the_text) { echo '<ul>'; echo '<li>'; if($the_link) { echo '<a href="' . $the_link . '" class="video" target="_blank">' . $the_text . '</a>'; } else { echo $the_text; } echo '</li>'; echo '</ul>'; } } else { echo get_page_content(34); } ?> </div> <p><a href="/resources/">+ Visit Resource Center - Test</a></p> </div> <?php } echo get_page_content(689); ?> <div class="clr"></div> <div class="blue-bars"> <a href="<?php bloginfo('template_directory');?>/more-info.php" class="more-info" rel="facebox">Request More Info</a> <a href="<?php bloginfo('template_directory');?>/resource-form.php?id=701000000009E" class="view-demos" rel="facebox">Schedule a Demo</a> </div> </div> <div id="content"> Here's the conditional php I tried inserting near the top of the code above that did not work: if ( in_category( 'blog' )) { <p>Does this show up?</p> } Any suggestions? I basically want to test individual posts and archive pages to see if they are in my particular category and then display unique sidebar info accordingly. Thanks! Link to comment https://forums.phpfreaks.com/topic/198047-testing-category-with-php-and-displaying-a-conditional-sidebar/ Share on other sites More sharing options...
Pikachu2000 Posted April 8, 2010 Share Posted April 8, 2010 Try it with echo . . . if( in_category('blog') ) { echo '<p>Does this show up</p>; } Link to comment https://forums.phpfreaks.com/topic/198047-testing-category-with-php-and-displaying-a-conditional-sidebar/#findComment-1039198 Share on other sites More sharing options...
poindexter Posted April 9, 2010 Author Share Posted April 9, 2010 Thanks, now I understand what "echo" means (pretty lame that I didn't even know that--thanks for being gracious!). I put that in and it still didn't work, so I got some help from a buddy. We got at least a little functionality that I'm looking for with the following code: <div class="sidebar"> <?php if (!is_search() && !is_page('Our Clients') && !is_archive()){ if($post->post_parent) { $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0&depth=1&exclude=85,87,89,181,97,184"); } else { $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0&depth=1&exclude=85,87,89,181,97,184"); } if ($children) { ?> <div class="panel links subnav"> <h3>In This Section</h3> <ul class="subnav"> <?php echo $children; ?> </ul> <p> </p> </div> <?php } } if(is_page('Our Clients') || in_category('Our Clients') || is_category('Our Clients')) { echo '<div class="panel links subnav">'; echo '<h3>In This Section</h3>'; echo '<ul class="subnav">'; wp_list_categories('child_of=21&title_li='); echo '</ul>'; echo '<p> </p>'; echo '</div>'; } if (!is_page('Resources')) { ?> <div class="panel featured-resource"> <h4>Featured Resource</h4> <div class="embed"> <?php $custom_fields = get_post_custom(); $featured_video_code = $custom_fields['Featured Video Code']; if($featured_video_code) { foreach ( $featured_video_code as $key => $value ) { $the_code = $value; } $featured_video_link = $custom_fields['Featured Video Link']; foreach ( $featured_video_link as $key => $value ) { $the_link = $value; } $featured_video_text = $custom_fields['Featured Video Text']; foreach ( $featured_video_text as $key => $value ) { $the_text = $value; } if($the_code) { echo $the_code; } if($the_text) { echo '<ul>'; echo '<li>'; if($the_link) { echo '<a href="' . $the_link . '" class="video" target="_blank">' . $the_text . '</a>'; } else { echo $the_text; } echo '</li>'; echo '</ul>'; } } //note: blog sidebar condition else if (is_category('Blog')) { //PUT YOUR CODE HERE // echo get_page_content(34); echo "test"; //END CODE HERE } ?> </div> <p><a href="/resources/">+ Visit Resource Center</a></p> </div> <?php } echo get_page_content(689); ?> <div class="clr"></div> <div class="blue-bars"> <a href="<?php bloginfo('template_directory');?>/more-info.php" class="more-info" rel="facebox">Request More Info</a> <a href="<?php bloginfo('template_directory');?>/resource-form.php?id=701000000009E" class="view-demos" rel="facebox">Schedule a Demo</a> </div> </div> <div id="content"> However, I'm still having some issues. Namely, I want to all the code except for the blog category related code from appearing when the category is set to blog. I tried moving the code after the blog sidebar condition up into the other conditional area, but the entire sidebar disappeared. Any other suggestions? Thanks again! Link to comment https://forums.phpfreaks.com/topic/198047-testing-category-with-php-and-displaying-a-conditional-sidebar/#findComment-1039697 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.