vc_map – Komplexe Post Abfrage Parameter
2 min read
Komplexe Post Abfrage für Custom Post Types und Kategorien. Sieht am Ende so aus:
<?php /* Shortcode: [kategorien_posts_slider] Autor: M.Ho / bundesweit.digital Version: 1.0 */ if ( ! defined( 'ABSPATH' ) ) { die( '-1' ); } function kategorien_posts_slider($atts, $content = null){ // Attribute einlesen, auf default setzen falls nicht angegeben $atts = shortcode_atts([ 'title' => '', 'link' => '', 'items' => '', 'css' => '' ], $atts); ?> <?php if ( list($args, $wp_query) = vc_build_loop_query($atts["items"]) ): ?> <?php while ( $wp_query->have_posts() ): ?> <?php $wp_query->the_post(); $post = new stdClass(); // Creating post object. $post->title = get_the_title($post->id); $post->thumbnail = get_the_post_thumbnail_url($post->id); $post->link = get_permalink($post->id); $post->content = get_the_content($post->id); $tags = get_the_terms( $post->id, 'category' ); ?> <div class="postsCatBlockLeft"> </div> <?php endwhile; ?> <?php wp_reset_postdata(); ?> <?php // HTML Output in Variable packen und zurück geben $output = ob_get_contents(); ob_end_clean(); return $output; } // Shortcode hinzufügen add_shortcode('kategorien_posts_slider', 'kategorien_posts_slider'); /* WPBakery den Shortcode beibringen und Datenfelder beschreiben für das Konfig-Feld REFERENZ: https://kb.wpbakery.com/docs/inner-api/vc_map/ */ if( function_exists('vc_map') ){ add_action( 'vc_before_init', function(){ vc_map( array( "name" => "Blog Slider", "description" => "", "base" => "kategorien_posts_slider", "class" => "", "icon" => "", "category" => "bundesweit.digital", "content_element" => true, "holder" => "div", "params" => array( array( "type" => "loop", "class" => "", "heading" => __( "Сlick here to create a list of posts", "posts-domain" ), "param_name" => "items", "value" => '', "description" => __( "Create posts list with Build Query button ", "posts-domain" ) ), array( 'type' => 'css_editor', 'heading' => 'CSS', 'param_name' => 'css', 'group' => 'Design Options', ), ), ) ); } ); } ?>
Powered by BetterDocs