Search Results for 'code'
-
Search Results
-
Out of the box, bbpress shows topics from a particular forum when you are on that forum’s archive page. Makes sense. If that forum has a sub-forum, it will link to those sub-forums, but it won’t show the actual topics from that sub-forum.
I’m trying to modify the default bbpress loop on a forum page (loop-topics.php) to include the sub-forum topics.
Here’s an explanation:
Forum A
Sub-forum A1
Sub-forum A2
Forum B
Sub-forum B1
Sub-forum B2
So when viewing Forum A’s archive page, I’d like to show topics from Forum A, sub-forum A1 and sub-forum A2.The code needs to be dynamic in order to work with whatever parent forum archive a user is on.
You can pass wp_query args into bb_has_topics(), but I can only only come up with code that shows topics from one forum – not multiple forums.
To better explain what I’m working with, here’s an example of a loop that grabs topics from the parent forum:
<?php $parents = get_post_ancestors( $post->ID ); $id = ($parents) ? $parents[count($parents)-1]: $post->ID; $parent = get_page( $id ); ?> <?php $bbp_loop_args = array('post_parent' => $parent->ID, 'post_type' => 'topic'); ?> <?php if ( bbp_has_topics($bbp_loop_args) ) : ?> <?php while ( bbp_topics() ) : bbp_the_topic(); ?> <?php bbp_get_template_part( 'loop', 'single-topic' ); ?> <?php endwhile; ?> <?php endif;?>Any ideas on how this can be achieved?
I wonder if i could add a function that displays a topic starter label for any topic author in a topic.
It would be cool so that say 5 pages in a topic, you could always know who started the topic if they kept the conversation going.
I know the function would most likely be put in a theme
functions.phpbut i wonder if it could go intoloop-single-reply.phpI feel like the function would use the topic started by function, mainly
get_topic_author<span class="bbp-topic-started-by"><?php printf( __( 'Started by: %1$s', 'bbpress' ), bbp_get_topic_author_link( array( 'size' => '14' ) ) ); ?></span>IT would be a nice feature to have
any help??
I spent so long trawling google for an answer to this question, so i am sharing what i came up with. It might not be beautiful code (i patched it together from a number of sources), but it works for me.
Basically, i have a list of forums on my forum home page. I just wanted to show the latest post within each forum as a teaser below the forum description – not just the title, but the excerpt, too. I can’t believe there’s nothing out there explaining how to do this. It seems like a pretty obvious format for the forum index.
The following snippet will output the latest reply, with post title and post link below the forum description. If there are no replies, it will output the latest topic instead.
function jag_add_last_reply() { { $jag_last_reply_id = bbp_get_forum_last_reply_id(); $jag_last_topic_id = bbp_get_forum_last_topic_id(); $new_args = array( 'post_type'=> 'reply', 'p' => $jag_last_reply_id ); $other_args = array( 'post_type'=> 'topic', 'p' => $jag_last_topic_id ); $nest_query = new WP_Query( $new_args ); $another_nest_query = new WP_Query( $other_args ); if ( $nest_query->have_posts() ) : while ( $nest_query->have_posts() ) : $nest_query->the_post(); $this_post_id=$post->ID; $this_post_title= get_the_title(); $this_post_content= get_the_excerpt(); $this_post_permalink= get_permalink(); ?> <a href="<?php echo $this_post_permalink; ?>"><h1><?php echo $this_post_title; ?></h1></a> <div class="the_content"><?php echo $this_post_content; ?></div> <?php endwhile; elseif ( $another_nest_query->have_posts() ) : while ( $another_nest_query->have_posts() ) : $another_nest_query->the_post(); $this_post_id=$post->ID; $this_post_title= get_the_title(); $this_post_content= get_the_content(); $this_post_permalink= get_permalink(); ?> <a href="<?php echo $this_post_permalink; ?>"><h1><?php echo $this_post_title; ?></h1></a> <div class="the_content"><?php echo $this_post_content; ?></div> <?php endwhile; endif; }} // Hook into action add_action('bbp_theme_after_forum_description','jag_add_last_reply');Just put this in your theme’s functions.php and it should do the trick. Haven’t figured out how to spit out multiple posts and replies for each forum yet, but this is all i needed. Good luck.



