Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feagture request: Don't repeat posts when multiple shortcode instances are used on the same page #174

Closed
ammist opened this issue Oct 26, 2017 · 6 comments

Comments

@ammist
Copy link

ammist commented Oct 26, 2017

Hi there,

I'm working on a site where we're using the display post shortcode with Genesis. I'm working on a filter to change the output of the shortcode so it doesn't repeat previously-displayed posts, using $_genesis_displayed_ids.

I wonder if this would be a feature you could add directly to the shortcode itself.

Thanks for this wonderful shortcode, it makes WordPress much easier to use!

@billerickson
Copy link
Owner

While there is not a parameter in the shortcode for it (ex: [display-posts unique="true"]), you should be able to add that functionality through the existing filters.

I think it makes sense for this to NOT be in the core plugin, so that you can add support for posts listed outside of the shortcode as well. For instance, on archive pages you could exclude all posts in the current loop from appearing in the shortcode added in the sidebar.

In your specific instance, Genesis is already storing the list of displayed post IDs in a global variable so we can leverage that. Anyone wanting to replicate this on a non-Genesis theme should add something like this to their theme.

To add this functionality using $_genesis_displayed_ids, use this code: https://www.billerickson.net/code/dps-exclude-displayed-posts/

@ammist
Copy link
Author

ammist commented Oct 27, 2017

Thank you Bill, the filter does what I wanted to do.

This would be super-helpful on WordPress.com, though, where we can't just add a filter.

@billerickson
Copy link
Owner

Hmm, I'll re-open the issue and consider adding it to the next release. You'll still need to use the above code to exclude non-Display Posts Shortcode posts (ex: the Genesis loop), but I could build this functionality into the plugin for when multiple shortcodes are being used.

@david154774
Copy link

I'm using wordpress without genesis. Can you explain how to avoid that the second shortcode exclude the result of the first one ?

[display-posts category="most-important" include_excerpt="true" excerpt_length="200" include_excerpt="true" excerpt_more="..." wrapper="div" posts_per_page="1"]

[display-posts include_excerpt="true" excerpt_length="200" include_excerpt="true" excerpt_more="..." wrapper="div" posts_per_page="9"]

@billerickson
Copy link
Owner

This code will work with any theme, not just Genesis themes.

What's unique about Genesis is it will include the main loop's post in that variable already, so if you're using this shortcode in the sidebar of your blog archive, it will exclude the main posts from the content area automatically.

But if all you're trying to do is exclude posts from the previous Display Posts Shortcode, the code linked above will work for all themes.

@david154774
Copy link

it works well! thank you !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants