CMS WordPress

[WordPress] ¿Cómo mostrar las imágenes thumbnail en el widget Últimas noticias?

[titulo]Get recent posts with thumbnail[/titulo]

WordPress incorpora de serie unos widgets bastante socorridos como un Buscador, un cajetín de HTML, otro de texto… y por supuesto, uno de Últimas entradas publicadas.

Aunque la mayor parte de los temas modifican la estética de estos widgets, puede ocurrir que el tema que tienes activado no le de la forma que te gustaría y lo deje por defecto, soso. Sin thumbnails.

En esta pequeña entrada vamos a explicarte cómo añadirlos:

 

[resumen]
  1. Con código
  2. A través de plugins
[/resumen]

 

[titulo]Con código[/titulo]

El archivo que declara este widget en cuestión, lo podemo encontrar en:

[codigo]/wp-includes/widgets/class-wp-widget-recent-post.php[/codigo]

Y concretamente, alrededor de la línea 81, estará el siguiente código:

<?php
		if ( $title ) {
			echo $args['before_title'] . $title . $args['after_title'];
		}
		?>
		<ul>
			<?php foreach ( $r->posts as $recent_post ) : ?>
				<?php
				$post_title = get_the_title( $recent_post->ID );
				$title      = ( ! empty( $post_title ) ) ? $post_title : __( '(no title)' );
				?>
				<li>
					<a href="<?php the_permalink( $recent_post->ID ); ?>"><?php echo $title ; ?></a>
					<?php if ( $show_date ) : ?>
						<span class="post-date"><?php echo get_the_date( '', $recent_post->ID ); ?></span>
					<?php endif; ?>
				</li>
			<?php endforeach; ?>
		</ul>

Es el que regula la estética del widget.

Para añadir un thumbnail, debemos llamar a la función:
[codigo]get_the_post_thumbnail(id_post, ‘tamaño’)[/codigo].

Siendo el [codigo]id_post[/codigo] el id del post cuyo thumbnail queremos mostrar.

Y el [codigo]’tamaño'[/codigo], el tamaño que tendrá la imagen. Pudiendo escoger entre:

  • post-thumbnail
  • post-medium
  • post-large
  • post-full

O cualquier otro que hayamos declarado.

Por lo tanto, para añadir un thumbnail al loop de posts, tendremoss que poner algo como:

<?php echo get_the_post_thumbnail($recent_post->ID, 'post-thumbnail') ?>

 

En nuestro caso, aprovechamos y organizamos un poco la maquetación para que quede todo más bonito:

<?php
		if ( $title ) {
			echo $args['before_title'] . $title . $args['after_title'];
		}
		?>
		<ul class="all-recent-post">
			<?php foreach ( $r->posts as $recent_post ) : ?>
				<?php
				$post_title = get_the_title( $recent_post->ID );
				$title      = ( ! empty( $post_title ) ) ? $post_title : __( '(no title)' );
				?>
				<li class="single-recent-post">
					<div class="recent-img">
						<a href="<?php the_permalink( $recent_post->ID ); ?>">
							<?php echo get_the_post_thumbnail($recent_post->ID, 'post-thumbnail') ?>
						</a>
					</div>
					
					<div class="recent-desc">
						<h6>
							<a href="<?php the_permalink( $recent_post->ID ); ?>"><?php echo $title; ?></a>
						</h6>
                        <?php if ( $show_date ) : ?>
							<span class="post-date"><?php echo get_the_date( '', $recent_post->ID ); ?></span>
						<?php endif; ?>
                    </div>	
				</li>
			<?php endforeach; ?>
		</ul>

 

[titulo]A través de plugins[/titulo]

Latest Post [Descargar]

Hace exactamente lo que acabamos de explicar en el apartado superior, con la ventaja de que además permite ordenar por fecha de publicación, número de comentarios, los más votados, etc

 

PE Recent Posts [Descargar]

Plugin muy versátil que permite un altísimo grado de personalización. Desde mostrar las últimas entradas de una categoría concreta, a personalizar el número de caracteres a mostrar de la entradilla (el excerpt), pasando por personalizar el tamaño de la imagen o mostrarlas en varias columnas.

 

Latest Tabs [Descargar]

Plugin muy popular que probablemente hayáis visto ya instalado en muchos medios. Crea un widget muy atractivo con 3 pestañas: Una para las últimas entradas, otra para las más comentadas y una tercera para las más votadas.

 

Widget Post Slider [Descargar]

Muestra las últimas entradas en un widget con slider. De esa forma no se ocupa tanto espacio y se da más protagonismo a la imagen del post.

Cristian Sarabia Martínez

Desde que a principios de los 90 mi padre desempolvó su Spectrum, no he dejado de probar y experimentar con la tecnología.

Enamorado del mundo web, Full Stack Developer de profesión y diseñador por devoción.

Ahora hago mis pinitos en esto del blogging para compartir con vosotros un poquito de todo lo que la comunidad me ha dado.

Escribir comentario

Haz clic aquí para dejar tu comentario

ThemeForest

Collaboratively harness market-driven processes whereas resource-leveling internal or "organic" sources. Competently formulate.

Calendar

febrero 2026
L M X J V S D
 1
2345678
9101112131415
16171819202122
232425262728  

RSS Meks Blog

  • How Adding Slack Bot Boosted Our Culture of Appreciation 3 julio, 2024
    Sweet Kudos is a Slack bot that enhances employee recognition, rewards, and celebrations within your team. It empowers team members to express gratitude and appreciation effortlessly by giving virtual Kudos. The post How Adding Slack Bot Boosted Our Culture of Appreciation appeared first on Meks.
    Dusan Milovanovic
  • 10 Best Knowledge Base & Wiki WordPress Themes 2021 15 septiembre, 2021
    Running a successful online business requires an exceptional WordPress knowledge base theme that organizes documentation and helps customers. Customization options, intuitive navigation, unique layouts, and fast responsiveness are just some of the features you need. The following 10 WordPress wiki themes represent the best options for 2021 and beyond. Explore the full range to determine […]
    Dusan Milovanovic
  • How to increase WordPress Memory Limit (quick fixes) 16 junio, 2021
    Here is a post about how to increase the memory limit in WordPress. Allowed memory size exhausted error message showed up in your WordPress installation? No worries – this is one of the most common errors in WordPress. You can apply an easy fix by increasing the memory limit in your PHP. Table of Contents […]
    Dusan Milovanovic
  • How to use (and why) WordPress sitemap plugin 1 marzo, 2021
    Did you know that by knowing how to use the WordPress sitemap plugin you can significantly improve your site’s visibility and traffic? Although it isn’t mandatory to have a sitemap on your site, having one significantly improves the site’s quality, crawlability and indexing. All this is important for better optimization, which is why we wanted […]
    Ivana Cirkovic
  • 22 free and premium podcast software for your show [2021 edition] 18 enero, 2021
    You’re determined to start or improve your podcast but don’t know which podcast software to use to really make it stand out? We’ve got you! #podcasting Top 22 free and premium podcast software for your show #WordPressTips #podcasting The post 22 free and premium podcast software for your show [2021 edition] appeared first on Meks.
    Ivana Cirkovic
  • Digital storytelling with WordPress – an all-in-one guide to make your web stories pop! 23 noviembre, 2020
    Wondering how to improve digital storytelling with WordPress and build more awareness and exposure of your business? Let our guide lead the way. The post Digital storytelling with WordPress – an all-in-one guide to make your web stories pop! appeared first on Meks.
    Ivana Cirkovic
  • How to use WordPress autoposting plugin to improve your visibility and SEO? 10 septiembre, 2020
    Did you know you can use the WordPress autoposting plugin for your content efforts and improve not only your time management but your business and visibility as well? The post How to use WordPress autoposting plugin to improve your visibility and SEO? appeared first on Meks.
    Ivana Cirkovic
  • How to create a personal branding site? Step-by-step DIY guide 15 agosto, 2020
    Looking for ways and means to create a personal branding site? Well, look no further ’cause we’re giving away all the how-to’s to do it yourselves! The post How to create a personal branding site? Step-by-step DIY guide appeared first on Meks.
    Ivana Cirkovic
  • Top 15 WordPress content plugins and tools to improve your visibility and rankings 16 julio, 2020
    Let’s take a look at some of the must-have WordPress content plugins and tools to use to improve both your UX and rankings. The post Top 15 WordPress content plugins and tools to improve your visibility and rankings appeared first on Meks.
    Ivana Cirkovic
  • WCEU 2020 recap – key takeaways from the biggest online WordPress conference 9 junio, 2020
    Missed WCEU 2020 and all the exciting stuff from there? Here are all the key takeaways and main points to remember so, take notes! The post WCEU 2020 recap – key takeaways from the biggest online WordPress conference appeared first on Meks.
    Ivana Cirkovic

Text

Distinctively utilize long-term high-impact total linkage whereas high-payoff experiences. Appropriately communicate 24/365.

Archives