From 7f6f84be9e15f93fe6f12ab50402a0053e7f6976 Mon Sep 17 00:00:00 2001 From: Monika Eftimova Date: Mon, 6 Oct 2014 05:11:57 +0300 Subject: [PATCH] Create transport shortcode --- functions.php | 102 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 68 insertions(+), 34 deletions(-) diff --git a/functions.php b/functions.php index 6b05b97..64937f7 100644 --- a/functions.php +++ b/functions.php @@ -13,7 +13,16 @@ register_nav_menus( 'footer-followus' => __('Follow us in:', 'initfest') ) ); -add_shortcode('sh-latest-posts', 'sh_latest_posts'); + +# Register all shortcodes +function register_shortcodes(){ + add_shortcode('sh-latest-posts', 'sh_latest_posts'); + add_shortcode('sponsors', 'sponsors_shortcode'); + add_shortcode('transport', 'transport_shortcode'); +} + +add_action( 'init', 'register_shortcodes'); + function sh_latest_posts($atts){ $atts = shortcode_atts( array( @@ -23,11 +32,12 @@ function sh_latest_posts($atts){ $result = '

'.$atts['label'].' | '.__('see all', 'initfest').'

'; - ob_start(); $news_args = array( 'catecory_name' => $cat, 'numberposts' => 3 ); $news = new WP_Query( $news_args ); + ob_start(); + if ( $news->have_posts() ) : while ( $news->have_posts() ) : $news->the_post(); ?> @@ -49,6 +59,62 @@ function sh_latest_posts($atts){ } + +# Create shortcode for sponsors +function sponsors_shortcode() { + $result= '

Спонсори

'; + + + $sponsors_args = array( 'post_type' => 'sponsors', 'orderby' => 'rand' ); + $sponsors = new WP_Query( $sponsors_args ); + + ob_start(); + + if ( $sponsors->have_posts() ) : + while ( $sponsors->have_posts() ) : $sponsors->the_post(); + if ( has_post_thumbnail() ) { + the_post_thumbnail(); + } else { + get_the_title(); + } + endwhile; + endif; + + $result .= ob_get_contents(); + ob_end_clean(); + + return $result; +} + + +# Create shortcode for transport methods +function transport_shortcode() { + $result= '

Място: Интерпред, София, България

'; + + $transport_args = array( 'post_type' => 'transportation' ); + $transport = new WP_Query( $transport_args ); + + ob_start(); + + if ( $transport->have_posts() ) : + while ( $transport->have_posts() ) : $transport->the_post(); +?> +


+ +
+ 'sponsors', 'orderby' => 'rand' ); - $sponsors = new WP_Query( $sponsors_args ); - - if ( $sponsors->have_posts() ) : - while ( $sponsors->have_posts() ) : $sponsors->the_post(); - if ( has_post_thumbnail() ) { - $output .= the_post_thumbnail(); - } else { - $output .= get_the_title(); - } - endwhile; - endif; - - return $output; - -} - - -# Register all shortcodes -function register_shortcodes(){ - add_shortcode('sponsors', 'sponsors_shortcode'); -} - -add_action( 'init', 'register_shortcodes'); - - ?>