function arhiva_hotarari_shortcode($atts) {
$atts = shortcode_atts(array(
‘categorie’ => ‘hotarari-ale-consiliului-local’
), $atts, ‘arhiva_hotarari’);
$args = array(
‘post_type’ => ‘post’,
‘posts_per_page’ => -1,
‘orderby’ => ‘date’,
‘order’ => ‘DESC’,
‘category_name’ => $atts[‘categorie’]
);
$query = new WP_Query($args);
if (!$query->have_posts()) return ‘Nu există documente în această categorie.’;
$docs_by_year = [];
$current_year = date(‘Y’);
while ($query->have_posts()) {
$query->the_post();
$post_date = get_the_date(‘Y-m-d’);
$date_obj = DateTime::createFromFormat(‘Y-m-d’, $post_date);
if (!$date_obj) continue;
$year = $date_obj->format(‘Y’);
$docs_by_year[$year][] = [
‘title’ => get_the_title(),
‘date’ => $date_obj->format(‘d.m.Y’),
‘link’ => get_permalink()
];
}
wp_reset_postdata();
if (empty($docs_by_year)) return ‘Nu s-au găsit documente.’;
// Asigură că anul curent este inclus
if (!array_key_exists($current_year, $docs_by_year)) {
$docs_by_year = [$current_year => []] + $docs_by_year;
}
krsort($docs_by_year); // sortare descrescătoare
// Generare HTML
$output = ‘
foreach (array_keys($docs_by_year) as $year) {
$active = ($year == $current_year) ? ‘active’ : ”;
$output .= ““;
}
$output .= ‘
‘;
$output .= ‘
foreach ($docs_by_year as $year => $docs) {
$display = ($year == $current_year) ? ‘block’ : ‘none’;
$output .= “
if (!empty($docs)) {
foreach ($docs as $doc) {
$output .= “
{$doc[‘title’]} – {$doc[‘date’]}
“;
}
} else {
$output .= “
Nu există documente pentru anul {$year}.
“;
}
$output .= ‘
‘;
}
$output .= ‘
‘;
// Stiluri și JS
$output .=
.ani-arhiva {
margin-bottom: 15px;
padding-bottom: 10px;
border-bottom: 2px solid #ccc;
display: flex;
flex-wrap: wrap;
gap: 10px;
}
.an-btn { padding: 8px 14px; background: #f1f1f1; border: 1px solid #ccc; cursor: pointer; border-radius: 4px; font-size: 18px; transition: all 0.3s ease; }
.an-btn:hover { background: #e1e1e1; }
.an-btn.active { background: #0073aa; color: white; border-color: #0073aa; }
#lista-documente { border: 2px solid black; padding: 15px; border-radius: 6px; margin-top: 15px; }
#lista-documente p { margin: 6px 0; font-size: 18px; }
@media (max-width: 600px) { .an-btn { font-size: 16px; } #lista-documente p { font-size: 16px; } }
HTML;
return $output;
}
add_shortcode(‘arhiva_hotarari’, ‘arhiva_hotarari_shortcode’);