112 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Located in Australia
  • Has sold $10,000+ on Envato Market
+3 more
ThemeChills says

Hi everyone,

Does anyone know what script I could use for a custom shortcode which will allow me to use the “exclude” attribute similar to how the gallery shortcode does it?

Essentially, I am creating a slider which needs to exclude certain images that have been uploaded through my custom post type.

Currently, all images get included which is not what I need.

Hope you can help, thanks.

Leo

112 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Located in Australia
  • Has sold $10,000+ on Envato Market
+3 more
ThemeChills says

Just following up on this thread to see if anyone would know how to go about doing this?

631 posts
  • Has been part of the Envato Community for over 3 years
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
ChapterThemes says

Why not let people only upload and setup images which need to be in the slider?

Or isn’t it a separate module/post type or something?

112 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Located in Australia
  • Has sold $10,000+ on Envato Market
+3 more
ThemeChills says

Why not let people only upload and setup images which need to be in the slider? Or isn’t it a separate module/post type or something?

So there are 2 sliders on the same page. I have setup the custom post type, where I can add all the corresponding images that will live in the slider.

Thing is, 1 slider needs to have 3 of the 6 images showing, and the other slider needs to do the same but in reverse.

Essentially, I want to replicate the functionality that the Gallery shortcode has, but cannot work it out.

I would like something like this:

[myshortcode exclude="21,32,43"]

Shortcode works, but it inherits ALL slides…does this clarify things?

1391 posts How's the surf doing?
  • Has referred 200+ members
  • Has sold $500,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+6 more
tommusrhodus says

Realistically you’d need to post your codebase so we can see exactly how you’re doing things, but assuming you want to go for an ID array as the above to exclude items, I’m sure you could explode that string into an Array, and then use Unset:

http://uk3.php.net/unset

To remove images with those ID’s from your original array to be output?

112 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Located in Australia
  • Has sold $10,000+ on Envato Market
+3 more
ThemeChills says

Here is my code, without the ability to exclude…this displays ALL slides in my flexslider sections.


function chills_get_slider() {

    $output = '<div class="flexslider">
    <ul class="slides">';

    query_posts('post_type=slides');

    if (have_posts()) : while (have_posts()) : the_post(); 

    $the_featured_image = get_the_post_thumbnail( $post->ID, 'full' );
    $the_caption            = get_the_content();

    $output.='<li>'.$the_featured_image.'<p class="flex-caption">'.$the_caption.'</p></li>';

    endwhile; 
    endif; 
    wp_reset_query();

    $output.= '</ul>
    </div>';

    return $output;
}

And this is how I call the above function to render the output.


function chills_slider_shortcode($attr, $content = null) {

    $output = chills_get_slider();
    return $output;
}

add_shortcode('chills_slider', 'chills_slider_shortcode');

686 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Provided great contribution to our forums
  • Has been a beta tester for an Envato feature
+4 more
Gareth_Gillman says

In the query posts you need to add the following:

'post__not_in' => array(6,2,8)

You would then grab the posts from the shortcode by using the Shortcode Attributes

1391 posts How's the surf doing?
  • Has referred 200+ members
  • Has sold $500,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+6 more
tommusrhodus says
112 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Located in Australia
  • Has sold $10,000+ on Envato Market
+3 more
ThemeChills says

Also, use WP_Query instead of query_posts: http://wordpress.stackexchange.com/questions/1753/when-should-you-use-wp-query-vs-query-posts-vs-get-posts

Thanks guys.

So would I use this like so:


$query = new WP_Query( 'post_type=slides' );

Still new to all this, so apologies for all the questions.

Thanks again.

112 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Located in Australia
  • Has sold $10,000+ on Envato Market
+3 more
ThemeChills says

In the query posts you need to add the following:
'post__not_in' => array(6,2,8)
You would then grab the posts from the shortcode by using the Shortcode Attributes

Thanks Gareth,

Though how would this work if I need the user to exclude the required post ID. I wouldn’t be able to hard code it like so as the ID could differ.

Thoughts?

by
by
by
by
by
by