ThemeShaper Forums » Thematic

[closed]

How can I exclude bbPress 'post_type=forum' posts within functions.php?

(11 posts)
  • Started 3 years ago by benfrain.com
  • Latest reply from benfrain.com
  • This topic is not resolved
  1. I have content loaded on single posts but I want to stop this content also showing in my bbPress (v2) forum posts which use the post_type=forums. I am trying to use this in my functions.php but the content is still showing:

    function single_post_nav() {
    if ( is_single() && !in_category(array('54', '55', '56', '57', '58')) && !is_category(array('54', '55', '56', '57', '58')) && $post->post_type != 'forum' ) { ?>

    Where am I going wrong? I have also tried:

    && $post_type != 'forum'

    Any pointers appreciated!

    Posted 3 years ago #
  2. hi ben! i don't think i understand your question quite right. where are you trying to exclude the posts from? if you take another stab at explaining it to me, i'll take a crack and trying to help.

    Posted 3 years ago #
  3. Hi Helga - trust you are well...

    This function should basically load a bunch of HTML as long as the post is a single post, isn't in one of those categories and, crucially, ISN'T a forum post.

    Only just installed bbPress but the only way I can see to exclude bbPress Forum posts from this function is by excluding them by the post_type.

    Does that clarify?

    Posted 3 years ago #
  4. ok, that helps a little. according to the codex is_single() will return true for single custom post types as well as regular posts.

    so i think what you are looking for is proper logic to test for post type, which is seen here
    http://codex.wordpress.org/Conditional_Tags#A_Post_Type

    but it your case it would just be negative

    if ( 'forum' != get_post_type() )

    or your first function looks like it would work if you just global $post inside the function. otherwise the $post variable is probably null, so the post_type object is likewise null and your condition is never met

    hope that does the trick

    Posted 3 years ago #
  5. Hi Helga,

    OK, that helped a lot thanks. Only issue I have now is that using if ( 'forum' != get_post_type() ) I get pages showing too (where using is_single() didn't bring any pages through). Can I use something like: if ( 'forum','page' != get_post_type() ) to prevent those showing?

    Posted 3 years ago #
  6. use both?

    if ( is_single() && 'forum' != get_post_type() )
    Posted 3 years ago #
  7. Well, I'm more stumped than usual (note: I'm perpetually stumped by PHP). So... I now have this...

    function single_post_nav() {
    global $post;
    if ( is_single() && 'forum' != get_post_type() && !in_category(array('54', '55', '56', '57', '58')) && !is_category(array('54', '55', '56', '57', '58')) ) { ?>
    	<div id="nav-below" class="navigation">
    		<div class="nav-previous"><?php previous_post_link_plus( array('order_by' => 'menu_order', 'order_2nd' => 'post_title', 'in_same_cat' => true, 'max_length' => 50 ) ) ?></div>
    		<div class="nav-next"><?php next_post_link_plus( array('order_by' => 'menu_order', 'order_2nd' => 'post_title', 'in_same_cat' => true, 'max_length' => 50 ) ) ?></div>
    	</div>
    
    	<p class="commentsSkip"><a href="#respond">Read the comments on this video &raquo;</a></p>
    
    <?php
    	echo '<h2>More from this channel:</h2>';
    	next_post_link_plus( array('order_by' => 'menu_order', 'order_2nd' => 'post_title', 'format' => '%link', 'in_same_cat' => true, 'thumb' => true, 'num_results' => 9) );
    
    	$cat = get_the_category();
    	$cat_link = get_category_link( $cat[0]->cat_ID );
    	echo '<p><a class="watchAll" href="' . $cat_link . '" title="View all videos in this channel">View all videos in this channel</a></p>';
    	}
    elseif ( is_single() && 'forum' != get_post_type()) {
    echo '<div>';
    }
    }
    add_action ('thematic_belowpost','single_post_nav');

    Which means that everything apart from the Forum section is working as it should.

    However, the bbPress forums are STILL loading in this chunk of HTML, which I don't quite understand? Is it because I'm using 'global $post' incorrectly? Or is it due to the is_single() over-riding the 'forum' != get_post_type() part somehow?

    I've noticed that if I use: if ( !is_single() && 'forum' != get_post_type()) then the forum displays as it should (but obviously the rest of the site falls apart...)

    Any other thoughts?

    Posted 3 years ago #
  8. ben, when you get to the end of your rope w/ an issue sometimes it is best to start back over again.

    for instance, i am wondering why you are on the thematic_belowpost hook instead of just overriding the regular below navigation function?

    i'd copy thematic_nav_below() into my functions.php, rename it to childtheme_override_nav_below() and then tweak the conditionals and then the output for each condition. i tested this on the product post type i happen to have installed locally...

    function childtheme_override_nav_below() {
    	if (is_single() && !in_category(array(54, 55, 56, 57, 58)) && 'forum' != get_post_type() ) { ?>
    		<div id="nav-below" class="navigation">BACON
    			<div class="nav-previous"><?php if (function_exists('previous_post_link_plus')) : previous_post_link_plus( array('order_by' => 'menu_order', 'order_2nd' => 'post_title', 'in_same_cat' => true, 'max_length' => 50 ) ) ; else: thematic_previous_post_link(); endif;?></div>
    			<div class="nav-next"><?php if (function_exists('next_post_link_plus')) : next_post_link_plus( array('order_by' => 'menu_order', 'order_2nd' => 'post_title', 'in_same_cat' => true, 'max_length' => 50 ) ); else: thematic_next_post_link(); endif; ?></div>
    		</div>
    
    		<p class="commentsSkip"><a href="#respond">Read the comments on this video &raquo;</a></p>
    
    		<h2>More from this channel:</h2>
    
    		<?php if (function_exists('next_post_link_plus')) : next_post_link_plus( array('order_by' => 'menu_order', 'order_2nd' => 'post_title', 'format' => '%link', 'in_same_cat' => true, 'thumb' => true, 'num_results' => 9) ); endif;
    
    		$cat = get_the_category();
    		$cat_link = get_category_link( $cat[0]->cat_ID ); ?>
    
    		<p><a class="watchAll" href="<?php echo $cat_link; ?>" title="View all videos in this channel">View all videos in this channel</a></p>
    
    <?php
    	} elseif (is_single()) { ?>
    
    			<div id="nav-below" class="navigation">
    				<div class="nav-previous"><?php thematic_previous_post_link() ?></div>
    				<div class="nav-next"><?php thematic_next_post_link() ?></div>
    			</div>
    
    <?php
    		} else { ?>
    		<div id="nav-below" class="navigation">NO BACON
                <?php if(function_exists('wp_pagenavi')) { ?>
                <?php wp_pagenavi(); ?>
                <?php } else { ?>
    			<div class="nav-previous"><?php next_posts_link(__('<span class="meta-nav">&laquo;</span> Older posts', 'thematic')) ?></div>
    			<div class="nav-next"><?php previous_posts_link(__('Newer posts <span class="meta-nav">&raquo;</span>', 'thematic')) ?></div>
    			<?php } ?>
    		</div>
    <?php
    	}
    }
    Posted 3 years ago #
  9. Hi Helga, thanks, as ever, for responding. The page navigation has already been disabled with this in the theme-functions.php:

    /*
     * Remove Above Navigation
     */
    function remove_pagenavigation(){
    	remove_action('thematic_navigation_above', 'thematic_nav_above', 2);
    	remove_action('thematic_navigation_below', 'thematic_nav_below', 2);
    }
    add_action('init','remove_pagenavigation');

    So I can't do it the way you suggest (Boo friggin' hoo!). However, just to test, I did try disabling the remove_navigation feature and adding the new 'childtheme_override_nav_below' function above but it made no difference. Still this content appears - utterly baffled!

    So i really am just bashing my fat head against the desk with this in utter frustration. I'm at the point where I'm considering simply adding an entirely different piece of forum software (and use a different DB etc) which is crazy but as I'm PHP-challenged (there should be a registered charity for sufferers) and I've looked at every page Google has regarding this subject (twice) I can't think what else to try.

    Any other thoughts/suggestions?

    Posted 3 years ago #
  10. i just switched my local install to thematic and installed the bbpress plugin. when viewing a single forum post there is no navigation below at all, so i'm out of ideas without looking more closely at your theme and the bbpress code. i still like the idea of using the override and then adding a condition for where you don't want it to display versus totally removing it and adding it back.

    if you want to move this to premium support (aka "buy helga meade") then feel free to email me your theme and i'll take a closer look.

    Posted 3 years ago #
  11. Hi Helga, sounds like a plan. I'm completely stumped by it. I'll email it over and wait to hear.

    Cheers - Ben

    Posted 3 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.