Alberto González Quintanilla Programador web

Alberto González

Desarrollador Web y Profesor de WordPress

(Actualizado) Mostrar los últimos 15 posts en los foros de bbpress
albgonzalez13
0 comentarios

Muchas veces queremos mostrar sólo los últimos posts en un foro, con está función podrás mostrar los últimos 15 mensajes de un foro de bbpress. Recuerda guardarla en tu bbpress-function.php de tu theme de bbpress.

function new_last_posts ($forums_ids) {
	global $wpdb;

	$url = $_SERVER['REQUEST_URI'];
	$variable = explode ('/',$url);
	$countURL = count($variable);

	if( is_numeric($variable[$countURL-2]) ) $paged = $variable[$countURL-2];
	else $paged = 1;
	

$posts_count = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_parent IN ( '" . join( '\',\'', $forums_ids ) . "' ) AND post_status = 'publish'  AND post_type = 'topic' " );
$inicio = 0;

if( $paged != 1 ){
	$inicio = ($paged-1)*15;
}


$forums_data = $wpdb->get_results("SELECT p1.* , (IF ((SELECT MAX(p2.post_date) FROM wp_posts p2 WHERE p2.post_parent = p1.ID AND p2.post_type = 'reply'), (SELECT MAX(p2.post_date) FROM wp_posts p2 WHERE p2.post_parent = p1.ID AND p2.post_type = 'reply') , p1.post_date )) AS LAST_POST FROM wp_posts p1 WHERE p1.post_parent IN ( $forosIDs ) AND p1.post_status = 'publish' AND p1.post_type = 'topic' ORDER BY LAST_POST DESC LIMIT $inicio,15");

?>
get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_parent = %d  AND post_status = 'publish'", $topic->ID ));


		// Buscamos cual es la última actividad
		$last_active = get_post_meta( $topic->ID, '_bbp_last_active_time', true );				
		if ( empty( $last_active ) ) {
 				$last_active = get_post_field( 'post_date', $topic->ID );
		} else {
			$last_active = bbp_get_topic_last_active_time( $topic->ID);
		}
		// Generamos la URL

		if ( !empty($topic->LAST_POST) ) $anchor = ''.bbp_get_time_since($topic->LAST_POST).'';
		else  $anchor = ''.bbp_get_time_since($topic->post_date).'';


	?>
	
Tema Mensajes Actualizado
post_title; ?>
"; if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo ""; if($paged > 1 && $showitems < $pages) echo ""; for ($i=1; $i <= $pages; $i++) { if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems )) { echo ($paged == $i)? "".$i."":"".$i.""; } } if ($paged < $pages && $showitems < $pages) echo ""; if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo ""; echo "
\n"; } }