128 posts
  • Has sold $10,000+ on Envato Market
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Located in Australia
+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

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

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

642 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?

128 posts
  • Has sold $10,000+ on Envato Market
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Located in Australia
+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?

1551 posts How's the surf doing?
  • Nominated Community Superstar of the month
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has been part of the Envato Community for over 3 years
  • Had an item featured on Envato Market
+7 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?

128 posts
  • Has sold $10,000+ on Envato Market
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Located in Australia
+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');

825 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+5 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

1551 posts How's the surf doing?
  • Nominated Community Superstar of the month
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has been part of the Envato Community for over 3 years
  • Had an item featured on Envato Market
+7 more
tommusrhodus says
128 posts
  • Has sold $10,000+ on Envato Market
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Located in Australia
+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.

128 posts
  • Has sold $10,000+ on Envato Market
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Located in Australia
+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?

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by