Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

125
Views
Mostrar la lista de publicaciones de la categoría según la categoría de publicaciones actual

¿Alguien sabe cómo puedo mostrar una lista de publicaciones de WordPress según la categoría actual de las páginas de publicaciones actuales?

Por ejemplo, si actualmente estoy en post333.html y la categoría en la que se encuentra la página es " Bebidas ".

¿Cómo obtendría el resto de las publicaciones en esa categoría para que se muestren en una lista como "temas sugeridos" en post333.html ?

Y si la publicación y la categoría cambian, también lo hará la lista.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

El siguiente código debe ir directamente a su archivo de plantilla.

 <?php // Get Other posts in same category $suggested_posts = get_posts( array( 'category__in' => wp_get_post_categories( $post->ID ), // Retrieve the list of categories for a post. 'numberposts' => 5, // Number of posts 'post__not_in' => array( $post->ID ) // Exclude current post ) ); // If post found if( $suggested_posts ) { foreach( $suggested_posts as $post ) { setup_postdata($post); ?> <ul> <li> <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a> <?php the_content('Read the rest of this entry &raquo;'); ?> </li> </ul> <?php } } wp_reset_postdata(); ?>

Si desea usarlo en cualquier lugar, puede crear un código abreviado como el siguiente.

 <?php function yourprefix_suggested_posts( $atts ){ // Get Other posts in same category $suggested_posts = get_posts( array( 'category__in' => wp_get_post_categories( $post->ID ), // Retrieve the list of categories for a post. 'numberposts' => 5, // Number of posts 'post__not_in' => array( $post->ID ) // Exclude current post ) ); // If post found if( $suggested_posts ) { foreach( $suggested_posts as $post ) { setup_postdata($post); ?> <ul> <li> <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a> <?php the_content('Read the rest of this entry &raquo;'); ?> </li> </ul> <?php } } wp_reset_postdata(); } add_shortcode( 'suggested_posts', 'yourprefix_suggested_posts' ); ?>

Más tarde, puede usar el código abreviado [suggested_posts] en cualquier lugar.

(No probado, pero debería funcionar).

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!