El otro día, preparando un blog para un cliente, Sergio me sorprendió con un truquito muy chulo para modificar la portada de un theme de modo que solo mostrara los posts de un autor concreto. Es una aplicación sencilla y eficaz que, dicho sea de paso, dejó muy contento al cliente.
Solo tienes que localizar el loop
del fichero index.php
de tu plantilla activa y modificarlo de este modo:
Índice de contenidos
Antes …
<div id="content" class="narrowcolumn"> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <div <?php post_class(); ?> id="post-<?php the_ID(); ?>"> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'kubrick'), the_title_attribute('echo=0')); ?>"><?php the_title(); ?></a></h2> <small><?php the_time(__('F jS, Y', 'kubrick')) ?> <!-- by <?php the_author() ?> --></small> <div class="entry"> <?php the_content(__('Read the rest of this entry »', 'kubrick')); ?> </div> <p class="postmetadata"><?php the_tags(__('Tags:', 'kubrick') . ' ', ', ', '<br />'); ?> <?php printf(__('Posted in %s', 'kubrick'), get_the_category_list(', ')); ?> | <?php edit_post_link(__('Edit', 'kubrick'), '', ' | '); ?> <?php comments_popup_link(__('No Comments »', 'kubrick'), __('1 Comment »', 'kubrick'), __('% Comments »', 'kubrick'), '', __('Comments Closed', 'kubrick') ); ?></p> </div> <?php endwhile; ?>
Después …
<div id="content" class="narrowcolumn"> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <?php $autor = get_the_author_nickname();?> <?php if ($autor != "admin") {?> <div <?php post_class(); ?> id="post-<?php the_ID(); ?>"> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'kubrick'), the_title_attribute('echo=0')); ?>"><?php the_title(); ?></a></h2> <small><?php the_time(__('F jS, Y', 'kubrick')) ?> <!-- by <?php the_author() ?> --></small> <div class="entry"> <?php the_content(__('Read the rest of this entry »', 'kubrick')); ?> </div> <p class="postmetadata"><?php the_tags(__('Tags:', 'kubrick') . ' ', ', ', '<br />'); ?> <?php printf(__('Posted in %s', 'kubrick'), get_the_category_list(', ')); ?> | <?php edit_post_link(__('Edit', 'kubrick'), '', ' | '); ?> <?php comments_popup_link(__('No Comments »', 'kubrick'), __('1 Comment »', 'kubrick'), __('% Comments »', 'kubrick'), '', __('Comments Closed', 'kubrick') ); ?></p> </div> <?php }?> <?php endwhile; ?>
Nota: para el ejemplo he usado el loop del theme por defecto de WordPress; Kubrick. El autor elegido para el ejemplo es admin
que, por supuesto, puedes sustituir por el que quieras. Las líneas añadidas son la 6, 7 y 18
¿Te gustó este artículo? ¡Ni te imaginas lo que te estás perdiendo en YouTube!
uoo muchas gracias compañeroo!!
Compañero, hay un error en el código
Parse error: syntax error, unexpected T_ENDWHILE
Que extraño; puse las líneas en su lugar y cambié a un autor en particular pero sigue desplegando todos los posts ._.