jkb-kv-hro/functions/childtheme-shortcodes.php

50 lines
1.1 KiB
PHP
Raw Permalink Normal View History

2020-12-17 14:12:01 +01:00
<?php
//Query Posts ***************
function grlp_tag_list($atts, $content = null) {
extract(shortcode_atts(array(
'aussehen' => '',
'schlagwort' => '',
), $atts));
global $wp_query,$paged,$post;
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$message = "";
if(!empty($schlagwort)){
$args = array(
'tag' => $schlagwort,
'category_name' => 'allgemein',
'posts_per_page' => 10,
'paged' => 1,
);
}
else {
$message = "Konnte kein Schlagwort finden. Bitte mit dem Attribut 'tag=\"&lt;schlagwort&gt;\"' im shortcode eintragen.";
}
$wp_query->query($args);
ob_start(); ?>
<?php if (!empty($message)):?>
<p style="color:#f44;"><?= $message ?></p>
<?php endif; ?>
<section class="clearfix insidelist <?php echo $aussehen;?>">
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<?php get_template_part( 'content-list', get_post_format() ); ?>
<?php endwhile; ?>
</section>
<?php $wp_query = null; $wp_query = $temp;
$content = ob_get_contents();
ob_end_clean();
return $content;
}
add_shortcode("schlagwort_liste", "grlp_tag_list");
?>