Created
February 19, 2016 12:20
-
-
Save ziemekpr0/f442616a2511aab517e1 to your computer and use it in GitHub Desktop.
Prosty plugin dodający shortcode do WordPress - [moja_galeria]. Podany shortcode możemy wkleić do strony lub wpisu. Plugin ma za zadanie pobrać strony-dzieci i wyświetlić ich miniaturki we wpisie.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Moja Galeria | |
Plugin URI: http://wpadmin.pl | |
Description: Prosty plugin dodający shortcode - [moja_galeria], dzięki któremu możemy wyświetlić 'galerie' stron, będących rodzicem wybranej strony. | |
Version: 0.1 | |
Author: ziemekpr0@gmail.com | |
License: GPL2 | |
License URI: https://www.gnu.org/licenses/gpl-2.0.html | |
*/ | |
function generate_my_gallery(){ | |
$query_args = array( | |
'post_type' => 'page', //chodzi nam o strony | |
'post_parent' => '1883', //tu nalezy podac identyfikator strony-rodzica | |
'post_status' => 'publish', //tylko opublikowane strony | |
'orderby' => 'date', //sortowanie wedlug daty publikacji | |
'order' => 'DESC' //malejaco - od najnowszych do najstarszych | |
); | |
$the_query = new WP_Query($query_args); | |
// The Loop | |
$html = ''; | |
if ($the_query->have_posts()) | |
{ | |
while ($the_query->have_posts()) | |
{ | |
$the_query->the_post(); | |
// jezeli strona ma obrazek wyrozniajacy | |
if(has_post_thumbnail()) | |
{ | |
$html .= '<a href=" ' . get_the_permalink() . '" class="thumbnail">'; | |
$html .= get_the_post_thumbnail(); | |
$html .= '</a>'; | |
} | |
} | |
} | |
else | |
{ | |
$html = 'Galeria jest pusta.'; | |
} | |
return $html; | |
} | |
add_shortcode('moja_galeria', 'generate_my_gallery'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment