Skip to content

Instantly share code, notes, and snippets.

@trishasalas
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trishasalas/9817612 to your computer and use it in GitHub Desktop.
Save trishasalas/9817612 to your computer and use it in GitHub Desktop.
bbPress Forums Loop Using get_posts();
<?php
function date_compare($a, $b)
{
$t1 = strtotime($a->post_date);
$t2 = strtotime($b->post_date);
return $t1 - $t2;
}
// Cloud Loop
function get_cloud_forums_loop() {
global $post;
$query1_args = array(
'post_type' => 'topic',
'post_status' => 'publish',
'post_parent' => 218688,
'posts_per_page' => 10
);
$query_1 = get_posts( $query1_args );
$query2_args = array(
'post_type' => 'topic',
'post_status' => 'publish',
'post_parent' => 143,
'posts_per_page' => 10
);
$query_2 = get_posts( $query2_args );
$query3_args = array(
'post_type' => 'topic',
'post_status' => 'publish',
'post_parent' => 218686,
'posts_per_page' => 10
);
$query_3 = get_posts( $query3_args );
$query4_args = array(
'post_type' => 'topic',
'post_status' => 'publish',
'post_parent' => 218687,
'posts_per_page' => 10
);
$query_4 = get_posts( $query4_args );
$posts = array_merge( $query_1, $query_2, $query_3, $query_4 );
usort($posts, 'date_compare');
$count = 0;
foreach ( $posts as $post ) {
$count++;
$userID = $post->post_author;
$content = $post->post_content;
$permalink = $post->post_name;
if ($count < 11){
?>
<div class="bbparent-<?php echo sanitize_title(get_the_title($post->post_parent)); ?>">
<h4><a href="http://domain.com/forums-archive/topic/'. $permalink .'">'. $post->post_title .'</a></h4>
<div class="forum-excerpt">
<p><?php echo wp_trim_words( $content, 15 ) ?></p>
</div>
<p class="topic-meta">Posted on <?php echo $post->post_date; ?> | by: <?php echo get_the_author_meta('display_name', $userID ); ?> | In the forum: <a href="<?php get_permalink();?>"><?php echo get_the_title($post->post_parent); ?></a> | <a href="http://domain.com/forums-archive/topic/<?php echo $permalink; ?>">Read More »</a></p>
</div>
<?php
}
}
}
function cloud_forums() {
echo get_cloud_forums_loop();
}
// data center loop
function get_data_center_forums_loop() {
global $post;
$query1 = array(
'post_type' => 'topic',
'post_status' => 'publish',
'post_parent' => 10,
'posts_per_page' => 3
);
$query_1 = get_posts( $query1 );
$query2_args = array(
'post_type' => 'topic',
'post_status' => 'publish',
'post_parent' => 218704,
'posts_per_page' => 3
);
$query_2 = get_posts( $query2_args );
$query3_args = array(
'post_type' => 'topic',
'post_status' => 'publish',
'post_parent' => 11,
'posts_per_page' => 3
);
$query_3 = get_posts( $query3_args );
$query4_args = array(
'post_type' => 'topic',
'post_status' => 'publish',
'post_parent' => 4,
'posts_per_page' => 3
);
$query_4 = get_posts( $query4_args );
$query5_args = array(
'post_type' => 'topic',
'post_status' => 'publish',
'post_parent' => 9,
'posts_per_page' => 3
);
$query_5 = get_posts( $query5_args );
$query6_args = array(
'post_type' => 'topic',
'post_status' => 'publish',
'post_parent' => 8,
'posts_per_page' => 3,
'order_by' => 'post_date'
);
$query_6 = get_posts( $query6_args );
$posts = array_merge( $query_1, $query_2, $query_3, $query_4, $query_5, $query_6 );
usort($posts, 'date_compare');
$count = 0;
foreach ( $posts as $post ) {
$count++;
$userID = $post->post_author;
$content = $post->post_content;
$permalink = $post->post_name;
if ($count < 11){
?>
<div class="bbparent-<?php echo sanitize_title(get_the_title($post->post_parent)); ?>">
<h4><a href="http://domain.com/forums-archive/topic/'. $permalink .'">'. $post->post_title .'</a></h4>
<div class="forum-excerpt">
<p><?php echo wp_trim_words( $content, 15 ) ?></p>
</div>
<p class="topic-meta">Posted on <?php echo $post->post_date; ?> | by: <?php echo get_the_author_meta('display_name', $userID ); ?> | In the forum: <a href="<?php get_permalink();?>"><?php echo get_the_title($post->post_parent); ?></a> | <a href="http://domain.com/forums-archive/topic/<?php echo $permalink; ?>">Read More »</a></p>
</div>
<?php
}
}
}
// Desktop & ITSM
function get_desktop_itsm_forums_loop() {
global $post;
$query1 = array(
'post_type' => 'topic',
'post_status' => 'publish',
'post_parent' => 218703,
'posts_per_page' => 10
);
$query_1 = get_posts( $query1 );
$query2_args = array(
'post_type' => 'topic',
'post_status' => 'publish',
'post_parent' => 122,
'posts_per_page' => 10
);
$query_2 = get_posts( $query2_args );
$query3_args = array(
'post_type' => 'topic',
'post_status' => 'publish',
'post_parent' => 6,
'posts_per_page' => 10
);
$query_3 = get_posts( $query3_args );
$posts = array_merge( $query_1, $query_2, $query_3 );
usort($posts, 'date_compare');
$count = 0;
foreach ( $posts as $post ) {
$count++;
$userID = $post->post_author;
$content = $post->post_content;
$permalink = $post->post_name;
if ($count < 11){
?>
<div class="bbparent-<?php echo sanitize_title(get_the_title($post->post_parent)); ?>">
<h4><a href="http://domain.com/forums-archive/topic/'. $permalink .'">'. $post->post_title .'</a></h4>
<div class="forum-excerpt">
<p><?php echo wp_trim_words( $content, 15 ) ?></p>
</div>
<p class="topic-meta">Posted on <?php echo $post->post_date; ?> | by: <?php echo get_the_author_meta('display_name', $userID ); ?> | In the forum: <a href="<?php get_permalink();?>"><?php echo get_the_title($post->post_parent); ?></a> | <a href="http://domain.com/forums-archive/topic/<?php echo $permalink; ?>">Read More »</a></p>
</div>
<?php
}
}
}
// Scripting
function get_scripting_forums_loop() {
global $post;
$query1 = array(
'post_type' => 'topic',
'post_status' => 'publish',
'post_parent' => 218705,
'posts_per_page' => 10
);
$query_1 = get_posts( $query1 );
$query2_args = array(
'post_type' => 'topic',
'post_status' => 'publish',
'post_parent' => 136,
'posts_per_page' => 10
);
$query_2 = get_posts( $query2_args );
$posts = array_merge( $query_1, $query_2 );
usort($posts, 'date_compare');
$count = 0;
foreach ( $posts as $post ) {
$count++;
$userID = $post->post_author;
$content = $post->post_content;
$permalink = $post->post_name;
if ($count < 11){
?>
<div class="bbparent-<?php echo sanitize_title(get_the_title($post->post_parent)); ?>">
<h4><a href="http://domain.com/forums-archive/topic/'. $permalink .'">'. $post->post_title .'</a></h4>
<div class="forum-excerpt">
<p><?php echo wp_trim_words( $content, 15 ) ?></p>
</div>
<p class="topic-meta">Posted on <?php echo $post->post_date; ?> | by: <?php echo get_the_author_meta('display_name', $userID ); ?> | In the forum: <a href="<?php get_permalink();?>"><?php echo get_the_title($post->post_parent); ?></a> | <a href="http://domain.com/forums-archive/topic/<?php echo $permalink; ?>">Read More »</a></p>
</div>
<?php
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment