Mostrar todas las publicaciones en la categoría actual

27 oct 2012, 09:39:27
Vistas: 15.2K
Votos: 1

Estoy buscando crear un comportamiento como el que se muestra en el siguiente enlace:

http://www.javaexperience.com/java-role-of-serialversionuid-in-serialization/

Aquí se muestran todas las publicaciones de la misma categoría. Actualmente está escrito manualmente en HTML, quiero replicar este comportamiento usando código PHP en mi single.php.

Listado de publicaciones por categoría en WordPress

A continuación está el código que he escrito hasta ahora:

<?php
$category = get_the_category();
   <ul>

query_posts('cat='.$category);
if ( have_posts() ) : while ( have_posts() ) : the_post();
   <li><a href="get_permalink( $id );">the_title();</a></li>
endwhile; endif;
   </ul>
<br/>

?>

¿Alguien puede ayudar a hacer que funcione?

0
Todas las respuestas a la pregunta 2
1

Prueba esto:

$cat = get_query_var('cat');
$PozCat = get_category ($cat);
$PozCat->id // nos da el ID de la categoría actual.

Luego usa este hook en tu consulta:

<ul>
   <?php
    $cat = get_query_var('cat');
    $PozCat = get_category ($cat);
    //$PozCat->id
    query_posts('posts_per_page=-1&cat='.$PozCat->id);
    if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    <li><a href="<?php the_permalink();?>"><?php the_title(); ?></a></li>

    <?php endwhile; endif; ?>
</ul>
27 oct 2012 11:48:55
Comentarios

funciona perfectamente, excepto por el error tipográfico en the_permalink()

Grant Grant
14 dic 2018 07:27:53
0
-2

Puedes hacer esto usando Wp_query() pasando el nombre de la categoría como argumento:

<?php $my_query = new WP_Query('category_name=mi_categoria&showposts=-1'); ?>

<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>

<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">

<?php the_title(); ?></a>

<?php endwhile; ?>
27 oct 2012 11:36:27