┌────────────────────────────────┐ │ ░░░ ░░▓ ░▓▓ ███ ▓▓░ ▓░░ │ │ ~ M O O N ~ │ └────────────────────────────────┘
prd-web-01.centraldc.gr
LOCATION:
/var/www/html/adconect/wp-content/plugins/insPostsList
☗ ROOT
↻ REFRESH
✎ EDIT FILE
EDITING: insPostsList.php
<?php /** * Plugin Name: Super Flexible Posts Shortcode (with Include Children) * Plugin URI: https://yourwebsite.com * Description: Προσθέτει το shortcode [latest] με πλήρη έλεγχο σε τύπο δημοσίευσης, αριθμό, κατηγορία (στατική ή __CURRENT__), ταξινομία, όρους, σειρά, ετικέτες διάταξης, μέγεθος μικρογραφίας, μήκος αποσπάσματος, εναλλαγές ορατότητας, προσαρμοσμένες κλάσεις και έλεγχο include_children. * * Προσθέτει ένα ισχυρό και επαναχρησιμοποιήσιμο shortcode [latest] για την εμφάνιση πρόσφατων δημοσιεύσεων με πλήρη έλεγχο σε τύπο δημοσίευσης, κατηγορίες, σχεδιασμό, λογική εξόδου και την ένταξη παιδικών όρων. * * 🔧 Shortcode: [latest] * * ✅ Χαρακτηριστικά: * - post_type="post" — Προσαρμοσμένος τύπος δημοσίευσης (π.χ. post, page, product) * - count="3" — Αριθμός δημοσιεύσεων προς εμφάνιση * - category="news" — Slug μίας κατηγορίας, ή χρήση category="__CURRENT__" για την πρώτη κατηγορία της τρέχουσας δημοσίευσης * - categories="news,tech" — Πολλαπλά slugs κατηγοριών, ή χρήση categories="__CURRENT__" για όλες τις κατηγορίες της τρέχουσας δημοσίευσης * - taxonomy="post_tag" — Όνομα προσαρμοσμένης ταξινομίας (π.χ. product_cat) * - terms="featured,new" — Slugs όρων για χρήση με προσαρμοσμένη ταξινομία * - order="DESC" — Κατεύθυνση ταξινόμησης: ASC ή DESC * - orderby="date" — Πεδίο ταξινόμησης: date, title, modified, rand, κλπ. * - exclude_current="true" — Εξαίρεση της τρέχουσας δημοσίευσης (σε προβολή μίας δημοσίευσης) * - class="latest-posts" — Κλάση CSS για το εξωτερικό περιτύλιγμα * - wrapper_tag="section" — Ετικέτα HTML για περιτύλιγμα δημοσιεύσεων (π.χ. div, section, ul) * - title_tag="h3" — Ετικέτα HTML για τίτλους δημοσιεύσεων (π.χ. h2, h4) * - excerpt_length="30" — Αριθμός λέξεων για το απόσπασμα * - thumbnail_size="medium" — Μέγεθος εικόνας (thumbnail, medium, large, full) * - show_excerpt="true" — Εμφάνιση αποσπάσματος (true/false) * - show_category="true" — Εμφάνιση κατηγορίας δημοσίευσης (true/false) * - show_thumbnail="true" — Εμφάνιση μικρογραφίας δημοσίευσης (true/false) * - no_posts_message="No posts found." — Μήνυμα όταν δεν βρέθηκαν δημοσιεύσεις * - include_children="true" — Συμπερίληψη δημοσιεύσεων από παιδικές κατηγορίες/όρους (true/false, προεπιλογή true) * * 💡 Παραδείγματα: * [flex_latest_posts count="5" category="__CURRENT__" class="custom-style"] * [flex_latest_posts post_type="product" taxonomy="product_cat" terms="featured" include_children="false"] * * Version: 2.3 * Author: Giannis Giannopoulos * Author URI: https://yourwebsite.com */ if (!defined('ABSPATH')) exit; // Global μεταβλητή για αποκλεισμό posts global $exclude_ids; $exclude_ids = array(); add_shortcode('latest', function ($atts) { global $exclude_ids; $atts = shortcode_atts([ 'post_type' => 'post', 'title' => 'Latest News', 'category' => '', 'categories' => '', 'taxonomy' => '', 'terms' => '', 'count' => 3, 'order' => 'DESC', 'orderby' => 'date', 'class' => 'block latest-posts', 'wrapper_tag' => 'section', 'title_tag' => 'h3', 'excerpt_length' => 30, 'thumbnail_size' => 'medium', 'show_excerpt' => 'true', 'show_category' => 'true', 'show_thumbnail' => 'true', 'exclude_current' => 'true', 'no_posts_message' => '', 'include_children' => 'true', 'exclude_shown' => 'false', 'track_shown' => 'false', ], $atts, 'flex_latest_posts'); // Έλεγχος αν είμαστε σε singular view και αν η τρέχουσα δημοσίευση έχει κατηγορίες if (is_singular()) { $post_cats = get_the_category(); if (empty($post_cats) && ($atts['category'] === '__CURRENT__' || $atts['categories'] === '__CURRENT__')) { return ''; // Δεν υπάρχουν κατηγορίες, επιστρέφουμε κενό } } $query_args = [ 'post_type' => sanitize_text_field($atts['post_type']), 'posts_per_page' => intval($atts['count']), 'order' => sanitize_text_field($atts['order']), 'orderby' => sanitize_text_field($atts['orderby']), 'no_found_rows' => true, ]; // Αποκλεισμός ήδη εμφανισμένων posts if (filter_var($atts['exclude_shown'], FILTER_VALIDATE_BOOLEAN) && !empty($exclude_ids)) { $query_args['post__not_in'] = $exclude_ids; } $include_children = filter_var($atts['include_children'], FILTER_VALIDATE_BOOLEAN); if ($atts['exclude_current'] === 'true' && is_singular()) { $current_id = get_the_ID(); $query_args['post__not_in'] = isset($query_args['post__not_in']) ? array_merge($query_args['post__not_in'], [$current_id]) : [$current_id]; } // Χειρισμός __CURRENT__ για κατηγορίες if (is_singular() && ($atts['category'] === '__CURRENT__' || $atts['categories'] === '__CURRENT__')) { $post_cats = get_the_category(); $cat_slugs = !empty($post_cats) ? wp_list_pluck($post_cats, 'slug') : []; if ($atts['category'] === '__CURRENT__' && !empty($cat_slugs)) { $query_args['tax_query'] = [ [ 'taxonomy' => 'category', 'field' => 'slug', 'terms' => [$cat_slugs[0]], 'include_children' => $include_children, ], ]; } if ($atts['categories'] === '__CURRENT__' && !empty($cat_slugs)) { $query_args['tax_query'] = [ [ 'taxonomy' => 'category', 'field' => 'slug', 'terms' => $cat_slugs, 'include_children' => $include_children, ], ]; } } else { if (!empty($atts['categories'])) { $query_args['tax_query'] = [ [ 'taxonomy' => 'category', 'field' => 'slug', 'terms' => array_map('trim', explode(',', $atts['categories'])), 'include_children' => $include_children, ], ]; } elseif (!empty($atts['category'])) { $query_args['tax_query'] = [ [ 'taxonomy' => 'category', 'field' => 'slug', 'terms' => [sanitize_text_field($atts['category'])], 'include_children' => $include_children, ], ]; } } if (!empty($atts['taxonomy'])) { if (isset($atts['terms']) && empty($atts['terms'])) { $query_args['tax_query'] = [[ 'taxonomy' => sanitize_text_field($atts['taxonomy']), 'field' => 'slug', 'terms' => ['non-existent-term-' . uniqid()], 'operator' => 'IN', ]]; } elseif (!empty($atts['terms'])) { $query_args['tax_query'] = [[ 'taxonomy' => sanitize_text_field($atts['taxonomy']), 'field' => 'slug', 'terms' => array_map('trim', explode(',', $atts['terms'])), 'include_children' => $include_children, ]]; } } $query = new WP_Query($query_args); ob_start(); if ($query->have_posts()) { if (filter_var($atts['track_shown'], FILTER_VALIDATE_BOOLEAN)) { foreach ($query->posts as $post) { $exclude_ids[] = $post->ID; } $exclude_ids = array_unique($exclude_ids); } printf('<%1$s class="latest-block %2$s">', esc_html($atts['wrapper_tag']), esc_attr($atts['class'])); if (!empty($atts['title'])) { printf('<%1$s class="%2$s">%3$s</%1$s>', esc_html($atts['title_tag']), 'block-title', esc_html($atts['title'])); } echo '<div class="items items-'.esc_attr($atts['class']).' grd">'; while ($query->have_posts()) : $query->the_post(); $title = get_the_title(); $category = get_the_category(); $category_name = !empty($category) ? $category[0]->name : ''; $thumbnail = get_the_post_thumbnail(get_the_ID(), $atts['thumbnail_size'], ['class' => 'post-thumbnail']); $excerpt = has_excerpt() ? get_the_excerpt() : wp_trim_words(get_the_content(), intval($atts['excerpt_length']), '...'); echo '<div class="item">'; if ($atts['show_thumbnail'] === 'true' && $thumbnail) { echo '<div class="post-thumbnail"><a href="' . esc_url(get_permalink()) . '">' . $thumbnail . '</a></div>'; } echo '<div class="post-content">'; if ($atts['show_category'] === 'true' && $category_name) { echo '<span class="post-category">' . esc_html($category_name) . '</span>'; } printf('<%1$s class="post-title"><a href="%2$s">%3$s</a></%1$s>', esc_html($atts['title_tag']), esc_url(get_permalink()), esc_html($title) ); if ($atts['show_excerpt'] === 'true') { echo '<div class="post-excerpt">' . wp_kses_post($excerpt) . '</div>'; } echo '</div></div>'; endwhile; echo '</div>'; printf('</%s>', esc_html($atts['wrapper_tag'])); wp_reset_postdata(); } else { if (empty($atts['no_posts_message'])) { ob_end_clean(); return ''; } echo '<p>' . esc_html($atts['no_posts_message']) . '</p>'; } return trim(ob_get_clean()); });
CANCEL
Name
Type
Size
Modified
Actions
↩ ..
DIR
—
—
📄 insPostsList.php
PHP
10.9 KB
2026-04-09 13:25
EDIT