Last active
August 29, 2015 14:04
-
-
Save partageit/f614423f7ee359b3239d to your computer and use it in GitHub Desktop.
Partage-it.com : amélioration du shortcode du carrousel d'articles pour WordPress avec Twitter Bootstrap
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 | |
/** | |
* The carousel shortcode | |
* | |
* This is the new version, accepting order criterias, limit, | |
* type of post and sticky posts | |
* Examples: | |
* - [carousel categories="my-categorie-slug,my-other-category-slug"] | |
* - [carousel tags="my-tag-slug" active="2" messageIfEmpty="No posts for this tag"] | |
* - [carousel tags="my-tag-slug" link="/my-tag-page/"] | |
* - [carousel tags="my-tag-slug" order="title" order="asc" limit="5" ] | |
* - [carousel tags="my-tag-slug" stickyposts="true" ] | |
* - [carousel posttypes="movie,actor" ] | |
* @param array $attr Attributes of the shortcode. | |
* @param content $content Content of the shortcode. Not used here. | |
* @return string HTML content to display gallery. | |
*/ | |
function bootstrapCarouselShortcode($attributes, $content) { | |
extract(shortcode_atts(array( | |
"categories" => null, | |
"tags" => null, | |
"classes" => null, | |
"id" => null, | |
"active" => 1, | |
"messageifempty" => "", | |
"link" => "post", | |
// new parameters | |
"limit" => null, | |
"order" => null, | |
"orderby" => null, | |
"posttypes" => "post", | |
"stickyposts" => null | |
), $attributes)); | |
$criterias = array("post_type" => explode(",", $posttypes)); | |
if ($stickyposts) { | |
$sticky = get_option("sticky_posts"); | |
$criterias["post__in"] = $sticky; | |
} | |
if ($categories) $criterias["category_name"] = $categories; | |
if ($tags) $criterias["tag"] = $tags; | |
if ($limit) $criterias["posts_per_page"] = $limit; | |
if ($order) $criterias["order"] = strtoupper($order); | |
if ($orderby) $criterias["orderby"] = $orderby; | |
return bootstrapCarousel($criterias, $classes, $id, $active, $messageIfEmpty, $link, false); | |
} | |
add_shortcode("carousel", "bootstrapCarouselShortcode"); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment