102 lines
4.9 KiB
PHP
102 lines
4.9 KiB
PHP
<?php
|
||
/**
|
||
* Plantilla para los archivos de categorías del blog.
|
||
*
|
||
* @package PowerServices
|
||
*/
|
||
|
||
get_header();
|
||
|
||
$current_page = max( 1, get_query_var( 'paged' ), get_query_var( 'page' ) );
|
||
$category_id = get_queried_object_id();
|
||
$category_posts = new WP_Query(
|
||
array(
|
||
'post_type' => 'post',
|
||
'post_status' => 'publish',
|
||
'posts_per_page' => 10,
|
||
'paged' => $current_page,
|
||
'cat' => $category_id,
|
||
'ignore_sticky_posts' => true,
|
||
)
|
||
);
|
||
?>
|
||
|
||
<main id="main-content">
|
||
<section class="bg-white pb-[70px] pt-[35px] text-black md:pb-[50px] md:pt-[50px]" aria-label="Entradas de <?php echo esc_attr( single_cat_title( '', false ) ); ?>">
|
||
<div class="container px-[50px] lg:px-8 md:w-[85%] md:px-0">
|
||
<?php if ( $category_posts->have_posts() ) : ?>
|
||
<div class="grid grid-cols-3 gap-x-[70px] gap-y-[40px] xl:gap-x-10 md:grid-cols-1 md:gap-y-5">
|
||
<?php while ( $category_posts->have_posts() ) : ?>
|
||
<?php
|
||
$category_posts->the_post();
|
||
$excerpt_source = has_excerpt()
|
||
? get_the_excerpt()
|
||
: wp_strip_all_tags( strip_shortcodes( get_the_content() ) );
|
||
$card_excerpt = wp_trim_words( $excerpt_source, 8, '...' );
|
||
?>
|
||
|
||
<article id="post-<?php the_ID(); ?>" <?php post_class( 'min-w-0' ); ?>>
|
||
<a class="block aspect-[346/280] w-full overflow-hidden bg-[#f3f3f3]" href="<?php the_permalink(); ?>" aria-label="<?php echo esc_attr( get_the_title() ); ?>">
|
||
<?php if ( has_post_thumbnail() ) : ?>
|
||
<?php the_post_thumbnail(
|
||
'large',
|
||
array(
|
||
'class' => 'h-full w-full object-cover object-center',
|
||
'loading' => 'lazy',
|
||
'sizes' => '(max-width: 767px) 85vw, 30vw',
|
||
)
|
||
); ?>
|
||
<?php endif; ?>
|
||
</a>
|
||
|
||
<h2 class="mt-[6px] text-[21px] font-bold uppercase leading-[1.4] md:text-[17.6px]">
|
||
<a class="transition-colors hover:text-[#f8b334]" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
|
||
</h2>
|
||
|
||
<time class="block text-[17px] leading-[22.8px] text-[#f8b930] md:text-[15px]" datetime="<?php echo esc_attr( get_the_date( DATE_W3C ) ); ?>">
|
||
<?php echo esc_html( get_the_date( 'j F, Y' ) ); ?>
|
||
</time>
|
||
|
||
<p class="mt-[10px] text-[19px] leading-[1.2] md:text-[16px]">
|
||
<?php echo esc_html( $card_excerpt ); ?>
|
||
</p>
|
||
</article>
|
||
<?php endwhile; ?>
|
||
</div>
|
||
|
||
<?php if ( $category_posts->max_num_pages > 1 ) : ?>
|
||
<?php
|
||
$total_pages = (int) $category_posts->max_num_pages;
|
||
$window_start = max( 1, min( $current_page - 1, $total_pages - 2 ) );
|
||
$window_end = min( $total_pages, $window_start + 2 );
|
||
?>
|
||
<nav class="mt-[50px] flex justify-center gap-[6px]" aria-label="Paginación de la categoría">
|
||
<?php if ( $current_page > 1 ) : ?>
|
||
<a class="inline-flex h-[35px] w-[35px] items-center justify-center bg-white text-[15px] font-semibold transition-colors hover:bg-[#f8b334] hover:text-white" href="<?php echo esc_url( get_pagenum_link( 1 ) ); ?>" aria-label="Primera página">«</a>
|
||
<a class="inline-flex h-[35px] w-[35px] items-center justify-center bg-white text-[15px] font-semibold transition-colors hover:bg-[#f8b334] hover:text-white" href="<?php echo esc_url( get_pagenum_link( $current_page - 1 ) ); ?>" aria-label="Página anterior">‹</a>
|
||
<?php endif; ?>
|
||
|
||
<?php for ( $page_number = $window_start; $page_number <= $window_end; $page_number++ ) : ?>
|
||
<?php if ( $page_number === $current_page ) : ?>
|
||
<span class="inline-flex h-[35px] w-[35px] items-center justify-center bg-[#f8b334] text-[15px] font-semibold text-white" aria-current="page"><?php echo esc_html( $page_number ); ?></span>
|
||
<?php else : ?>
|
||
<a class="inline-flex h-[35px] w-[35px] items-center justify-center bg-white text-[15px] font-semibold transition-colors hover:bg-[#f8b334] hover:text-white" href="<?php echo esc_url( get_pagenum_link( $page_number ) ); ?>"><?php echo esc_html( $page_number ); ?></a>
|
||
<?php endif; ?>
|
||
<?php endfor; ?>
|
||
|
||
<?php if ( $current_page < $total_pages ) : ?>
|
||
<a class="inline-flex h-[35px] w-[35px] items-center justify-center bg-white text-[15px] font-semibold transition-colors hover:bg-[#f8b334] hover:text-white" href="<?php echo esc_url( get_pagenum_link( $current_page + 1 ) ); ?>" aria-label="Página siguiente">›</a>
|
||
<a class="inline-flex h-[35px] w-[35px] items-center justify-center bg-white text-[15px] font-semibold transition-colors hover:bg-[#f8b334] hover:text-white" href="<?php echo esc_url( get_pagenum_link( $total_pages ) ); ?>" aria-label="Última página">»</a>
|
||
<?php endif; ?>
|
||
</nav>
|
||
<?php endif; ?>
|
||
<?php else : ?>
|
||
<p class="py-24 text-center text-[19px]">No hay artículos publicados en esta categoría.</p>
|
||
<?php endif; ?>
|
||
<?php wp_reset_postdata(); ?>
|
||
</div>
|
||
</section>
|
||
</main>
|
||
|
||
<?php get_footer(); ?>
|