Muestra los Posts Type en tu Sidebar


Muestra tus Custom Post Type más recientes de una forma muy simple en tu Sidebar.

Función

La función solo tiene el argumento $args = '' que es mixto. Esto quiere decir que vamos a utilizar los parámetros como cadena o como un arreglo.

$number // Cantidad de Posts Type a mostrar (Mínimo 1 y Máximo 15)
$post_type // Post Type a mostrar

Tan solo agrega la siguiente función en tu archivo function.php.

function listing_posts_type( $args = '' ) {

	$defaults = array(
		'number' => 5,
		'post_type' => 'post'
	);

	$r = wp_parse_args( $args, $defaults );

	if ( !$number = (int) $r['number'] )
		$number = 10;

	else if ( $number < 1 )
		$number = 1;

	else if ( $number > 15 )
		$number = 15;

	$r_query = new WP_Query( array( 'post_type' => $r['post_type'],
									'showposts' => $number,
									'nopaging' => 0,
									'post_status' => 'publish',
									'caller_get_posts' => 1
							) );

	if ( $r_query->have_posts() ) :

		while ( $r_query->have_posts() ) :
			$r_query->the_post(); ?>
			<li><a href="<?php the_permalink() ?>" title="<?php echo esc_attr( get_the_title() ); ?>"><?php the_title(); ?></a></li> <?php

		endwhile;

		wp_reset_postdata();

	endif;
}

Uso

<?php listing_posts_type(); ?>

Vamos a utilizar el Post Type Videos de ejemplos en la publicación: Custom Post Type.

<h3>Screencast</h3>
<ul>
<?php listing_posts_type( 'post_type=videos' ); ?>
</ul>
<h3>Screencast</h3>
<ul>
<?php listing_posts_type( array( 'post_type' => 'videos' ) ); ?>
</ul>
Listing Post Type

Ejemplo en Twenty Ten

Posted in

Leave a Reply