143 lines
3.5 KiB
PHP
143 lines
3.5 KiB
PHP
<?php
|
|
/**
|
|
* Blog listing and single helpers.
|
|
*/
|
|
|
|
function turquesa_blog_date( $post = null ) {
|
|
$post = get_post( $post );
|
|
if ( ! $post ) {
|
|
return '';
|
|
}
|
|
|
|
$timestamp = get_post_timestamp( $post );
|
|
if ( ! $timestamp ) {
|
|
return '';
|
|
}
|
|
|
|
$months = array(
|
|
1 => 'enero',
|
|
2 => 'febrero',
|
|
3 => 'marzo',
|
|
4 => 'abril',
|
|
5 => 'mayo',
|
|
6 => 'junio',
|
|
7 => 'julio',
|
|
8 => 'agosto',
|
|
9 => 'septiembre',
|
|
10 => 'octubre',
|
|
11 => 'noviembre',
|
|
12 => 'diciembre',
|
|
);
|
|
|
|
$day = (int) wp_date( 'j', $timestamp );
|
|
$month = (int) wp_date( 'n', $timestamp );
|
|
$year = wp_date( 'Y', $timestamp );
|
|
$label = isset( $months[ $month ] ) ? $months[ $month ] : wp_date( 'F', $timestamp );
|
|
|
|
return $day . ' ' . $label . ', ' . $year;
|
|
}
|
|
|
|
function turquesa_blog_byline() {
|
|
return 'Turquesa Digital';
|
|
}
|
|
|
|
function turquesa_blog_category_id() {
|
|
$term = get_term_by( 'slug', 'blog', 'category' );
|
|
return $term ? (int) $term->term_id : 0;
|
|
}
|
|
|
|
function turquesa_blog_posts_query( $args = array() ) {
|
|
$defaults = array(
|
|
'post_type' => 'post',
|
|
'post_status' => 'publish',
|
|
'posts_per_page' => 20,
|
|
'ignore_sticky_posts' => true,
|
|
'no_found_rows' => true,
|
|
);
|
|
|
|
if ( empty( $args['cat'] ) && empty( $args['category_name'] ) && turquesa_blog_category_id() ) {
|
|
$defaults['category_name'] = 'blog';
|
|
}
|
|
|
|
return new WP_Query( wp_parse_args( $args, $defaults ) );
|
|
}
|
|
|
|
function turquesa_blog_render_recent( $exclude_id = 0, $limit = 5 ) {
|
|
$query = turquesa_blog_posts_query(
|
|
array(
|
|
'posts_per_page' => $limit,
|
|
'post__not_in' => $exclude_id ? array( (int) $exclude_id ) : array(),
|
|
)
|
|
);
|
|
|
|
if ( ! $query->have_posts() ) {
|
|
return;
|
|
}
|
|
?>
|
|
<ul class="blog-recent">
|
|
<?php
|
|
while ( $query->have_posts() ) :
|
|
$query->the_post();
|
|
?>
|
|
<li>
|
|
<a class="blog-recent-item" href="<?php the_permalink(); ?>">
|
|
<?php
|
|
if ( has_post_thumbnail() ) {
|
|
the_post_thumbnail(
|
|
'medium',
|
|
array(
|
|
'alt' => '',
|
|
'width' => 84,
|
|
'height' => 64,
|
|
'decoding' => 'async',
|
|
)
|
|
);
|
|
}
|
|
?>
|
|
<span>
|
|
<em><?php echo esc_html( turquesa_blog_date() ); ?></em>
|
|
<strong><?php the_title(); ?></strong>
|
|
</span>
|
|
</a>
|
|
</li>
|
|
<?php endwhile; ?>
|
|
</ul>
|
|
<?php
|
|
wp_reset_postdata();
|
|
}
|
|
|
|
function turquesa_blog_render_aside( $args = array() ) {
|
|
$exclude_id = isset( $args['exclude_id'] ) ? (int) $args['exclude_id'] : 0;
|
|
$excerpt = isset( $args['excerpt'] ) ? (string) $args['excerpt'] : '';
|
|
?>
|
|
<aside class="blog-aside" aria-label="Artículos recientes">
|
|
<div class="blog-widget">
|
|
<h2 class="blog-widget-title">Artículos Recientes</h2>
|
|
<?php turquesa_blog_render_recent( $exclude_id, 5 ); ?>
|
|
</div>
|
|
<div class="blog-widget blog-widget-cta">
|
|
<h2 class="blog-widget-title">Diagnóstico</h2>
|
|
<p>Si un artículo describe tu caso, el siguiente paso es una revisión de sitio, keywords y métrica dueña.</p>
|
|
<a href="/#diagnostico">Pedir revisión →</a>
|
|
</div>
|
|
<?php if ( $excerpt ) : ?>
|
|
<div class="blog-widget">
|
|
<h2 class="blog-widget-title">Este Artículo</h2>
|
|
<p><?php echo esc_html( $excerpt ); ?></p>
|
|
<a href="<?php echo esc_url( home_url( '/blog/' ) ); ?>">Ver todo el blog →</a>
|
|
</div>
|
|
<?php endif; ?>
|
|
</aside>
|
|
<?php
|
|
}
|
|
|
|
function turquesa_blog_disable_toc_plus( $content ) {
|
|
if ( is_singular( 'post' ) && in_category( 'blog' ) && shortcode_exists( 'no_toc' ) ) {
|
|
return '[no_toc]' . $content;
|
|
}
|
|
|
|
return $content;
|
|
}
|
|
add_filter( 'the_content', 'turquesa_blog_disable_toc_plus', 1 );
|
|
|