Skip to content

Instantly share code, notes, and snippets.

@Alimir
Last active December 12, 2020 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Alimir/d5c03dfacd0594b4e9bf51dffaed7aa1 to your computer and use it in GitHub Desktop.
Save Alimir/d5c03dfacd0594b4e9bf51dffaed7aa1 to your computer and use it in GitHub Desktop.
wp ulike medipress example
<?php
//show it on single media page
add_action( 'mpp_media_meta', 'mpp_wpulike_show_button' );
//show it in lightbox
add_action( 'mpp_lightbox_media_meta', 'mpp_wpulike_show_button' );
function mpp_wpulike_show_button() {
echo wp_ulike('put');
}
function wp_ulike_mediapress_shortcode(){
$post__in = wp_ulike_get_popular_items_ids(array(
'type' => 'post',
'rel_type' => 'attachment',
'status' => array('like','dislike'),
'period' => 'all',
"offset" => 1,
"user_id" => '',
"limit" => 10
));
if( empty( $post__in ) ){
return __( 'Sorry, no media found.' );
}
$args = array(
'in' => $post__in,
'orderby' => 'post__in',
'per_page' => 10
);
$the_query = new MPP_Media_Query( $args );
ob_start();
if ( $the_query->have_media() ) : ?>
<!-- the loop -->
<?php while ( $the_query->have_media() ) : $the_query->the_media(); ?>
<div class="mpp-u <?php mpp_media_class( mpp_get_media_grid_column_class() );?>">
<div class='mpp-item-entry mpp-media-entry mpp-photo-entry'>
<a href="<?php mpp_media_permalink() ;?>" <?php mpp_media_html_attributes( array( 'class' => 'mpp-item-thumbnail mpp-media-thumbnail mpp-photo-thumbnail' ) ); ?>>
<img src="<?php mpp_media_src( 'thumbnail' ) ;?>" alt="<?php echo esc_attr( mpp_get_media_title() );?> "/>
</a>
</div>
</div>
<?php endwhile; ?>
<!-- end of the loop -->
<?php mpp_reset_media_data(); ?>
<?php else : ?>
<p><?php _e( 'Sorry, no media found.' ); ?></p>
<?php endif;
return ob_get_clean();
}
add_shortcode ('mmp_top_attachments', 'wp_ulike_mediapress_shortcode');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment