jchristopher / attachments

[WordPress Plugin] Attachments allows you to simply append any number of items from your WordPress Media Library to Posts, Pages, and Custom Post Types
wordpress.org/extend/plugins/attachments/
GNU General Public License v2.0
241 stars 78 forks source link

Shuffle Attachments #160

Closed vanthuanqs closed 6 years ago

vanthuanqs commented 8 years ago

It will be good if the plugin have a function to shuffle attachments before get them in while loop. Example:

<?php
$attachments = new Attachments( 'attachments', 123 );
$attachments->shuffle();
?>
<?php if( $attachments->exist() ) : ?>
    <h3>Attachments</h3>
    <ul>
        <?php while( $attachment = $attachments->get() ) : ?>
            <li>
                <pre><?php print_r( $attachment ); ?></pre>
            </li>
        <?php endwhile; ?>
    </ul>
<?php endif; ?>

At my own work, I edit and add this function to Main Attachments Class

/**
* Shuffle attachments
*
* @return null
*/
public function shuffle() {
    shuffle($this->attachments);
}
orionrush commented 8 years ago

I like this, and will probably implement it myself. Two thoughts:

  1. Offer a Pull Request and make it easy for Jonathan to review it and add it to the plugin.
  2. Rather than modify the plugin code directly, extend the class to add your own method (function). This could be done in your own helper plugin that loads after the Attachments plugin, or in your theme's functions.php. This way if there is an Attachments update, your custom modification isn't overwritten.
jchristopher commented 6 years ago

Hi there yes please see these docs