Create sponsors shortcode

This commit is contained in:
Monika Eftimova 2014-10-05 08:42:32 +03:00
parent 872dccd39e
commit cb6ac254b6
2 changed files with 35 additions and 19 deletions

View File

@ -15,24 +15,7 @@
</div> </div>
<div class="col2"> <div class="col2">
<h3>Спонсори</h3> <h3>Спонсори</h3>
<?php <?php echo do_shortcode( '[sponsors]' ); ?>
$sponsors_args = array( 'post_type' => 'sponsors', 'orderby' => 'rand' );
$sponsors = new WP_Query( $sponsors_args );
if ( $sponsors->have_posts() ) :
while ( $sponsors->have_posts() ) : $sponsors->the_post();
if ( has_post_thumbnail() ) {
?>
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a>
<?php
} else {
?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php
}
endwhile;
endif;
?>
</div> </div>
</section> </section>

View File

@ -179,4 +179,37 @@ function transportation_posttype() {
add_action( 'init', 'transportation_posttype' ); add_action( 'init', 'transportation_posttype' );
# Create shortcode for sponsors
function sponsors_shortcode() {
global $post;
$output = '';
$sponsors_args = array( 'post_type' => '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');
?> ?>