function cruzamundos_newsletter_posts( $atts ) { $atts = shortcode_atts( array( 'number' => 15, 'days' => 7, ), $atts, 'noptin_recent_7_days' ); $max_posts = intval( $atts['number'] ); // Data limite $date_limit = date( 'Y-m-d H:i:s', strtotime( '-' . intval( $atts['days'] ) . ' days' ) ); /* * Encontrar o ID REAL da categoria "Oportunidades". * Primeiro pelo nome, depois pelo slug. */ $opportunities_term = get_term_by( 'name', 'Oportunidades', 'category' ); if ( ! $opportunities_term ) { $opportunities_term = get_term_by( 'slug', 'oportunidades', 'category' ); } $opportunities_id = $opportunities_term ? intval( $opportunities_term->term_id ) : 0; /* * Buscar os posts recentes. * Mantemos a ordem cronológica original. */ $query = new WP_Query( array( 'posts_per_page' => -1, 'post_status' => 'publish', 'orderby' => 'date', 'order' => 'DESC', 'date_query' => array( array( 'after' => $date_limit, 'inclusive' => true, ), ), ) ); if ( ! $query->have_posts() ) { return '

Sem posts recentes para mostrar.

'; } /* * Criar dois grupos. */ $normal_posts = array(); $opportunity_posts = array(); while ( $query->have_posts() ) { $query->the_post(); $post_id = get_the_ID(); // Exactamente como no código original: // posts sem imagem não entram. if ( ! has_post_thumbnail( $post_id ) ) { continue; } /* * Se o post pertence à categoria Oportunidades, * vai para o segundo grupo. */ if ( $opportunities_id && has_category( $opportunities_id, $post_id ) ) { $opportunity_posts[] = $post_id; } else { $normal_posts[] = $post_id; } } wp_reset_postdata(); /* * AQUI está a alteração: * * 1. todos os posts normais * 2. depois Oportunidades * * E só depois limitamos aos 15. */ $post_ids = array_merge( $normal_posts, $opportunity_posts ); $post_ids = array_slice( $post_ids, 0, $max_posts ); /* * Construção do HTML */ $output = ''; foreach ( $post_ids as $post_id ) { $post = get_post( $post_id ); setup_postdata( $post ); $title = get_the_title(); $permalink = get_permalink(); $excerpt = get_the_excerpt(); // Data setlocale( LC_TIME, 'pt_PT.UTF-8' ); $post_date = ucfirst( strftime( '%A, %e de %B', strtotime( get_the_date( 'Y-m-d' ) ) ) ); $post_date = preg_replace_callback( '/de (\w+)/u', function( $m ) { return 'de ' . mb_convert_case( $m[1], MB_CASE_TITLE, 'UTF-8' ); }, $post_date ); // Primeira categoria $categories = get_the_category(); $category_name = ''; if ( ! empty( $categories ) ) { $category_name = esc_html( $categories[0]->name ); } // Imagem $thumbnail_url = get_the_post_thumbnail_url( $post_id, 'medium' ); $output .= '
'; $output .= '
'; $output .= ''; $output .= '' . esc_attr( $title ) . ''; $output .= ''; $output .= '
'; $output .= '
'; $output .= ''; $output .= '
'; $output .= esc_html( $title ); $output .= '
'; $output .= '
'; $output .= '
'; $output .= $post_date; $output .= '
'; $output .= '

'; $output .= esc_html( $excerpt ); $output .= '

'; $output .= '
Na categoria '; $output .= $category_name; $output .= '
'; $output .= '
'; $output .= '
'; } wp_reset_postdata(); return $output; } add_shortcode( 'noptin_recent_7_days', 'cruzamundos_newsletter_posts' ); Budismo – Cruzamundos https://www.cruzamundos.com O Mundo da Viagem em Português Sat, 12 Sep 2026 14:06:28 +0000 pt-PT hourly 1 https://wordpress.org/?v=7.0.2 49198855 Locais: Templo Otagi Nenbutsu-ji https://www.cruzamundos.com/locais-templo-otagi-nenbutsu-ji/ https://www.cruzamundos.com/locais-templo-otagi-nenbutsu-ji/#respond Wed, 20 May 2020 10:00:00 +0000 https://www.cruzamundos.com/?p=28165 https://www.cruzamundos.com/locais-templo-otagi-nenbutsu-ji/feed/ 0 28165