Skip to content

Instantly share code, notes, and snippets.

View alexmangini's full-sized avatar

Alex Mangini alexmangini

View GitHub Profile
@alexmangini
alexmangini / star-rating.php
Created March 1, 2019 19:58 — forked from robertdevore/star-rating.php
The PHP file that's called as $ajax_url in the star-rating.js file
<?php
function my_function_name() {
$postid = $_POST['postid'];
$rating = $_POST['rating'];
update_post_meta( $postid, 'delivery_rating', $rating );
wp_die();
}
add_action( 'wp_ajax_my_function_name', 'my_function_name' );
@alexmangini
alexmangini / star-rating.js
Created March 1, 2019 19:56 — forked from robertdevore/star-rating.js
Star rating script code example.
$(function() {
$('.driver-rating').barrating({
theme: 'fontawesome-stars',
initialRating: "<?php echo $averageRating; ?>",
showSelectedRating: true,
// onSelect is what triggers the saving of the rating.
onSelect: function(value, text, event) {
// Get element id by data-id attribute
var el = this;
function kol_md_popups() {
if ( ! is_page( 'md-popups' ) )
return;
?>
<style type="text/css">
@media all and (min-width: 1000px) {
.md-popups-content {
float: right;
width: 546px;
@alexmangini
alexmangini / functions.php
Last active August 29, 2015 14:24
List categories by post count — WordPress
<?php
/**
* Reorders get_categories() to list categories by
* the most posts to least.
*
* Example use: listing the most popular categories
* on your blog. print_r() function to see results.
*/
function kol_most_active_categories( $args = null ) {
( function() {
document.getElementById( 'md_no_sidebar' ).onchange = function( e ) {
document.getElementById( 'md_custom_sidebar_option' ).style.display = this.checked ? 'none' : 'block';
}
} )();
@alexmangini
alexmangini / admin-scripts.js
Last active August 29, 2015 14:06
Create multiple image upload fields on any admin options screen using the WordPress media manager overlay.
/**
* Based off Thomas Griffin's New Media Image Uploader.
* Thanks for that, man.
* https://github.com/thomasgriffin/New-Media-Image-Uploader
*/
jQuery( document ).ready( function( $ ) {
var kol_media_frame;
@alexmangini
alexmangini / gist:11133172
Created April 21, 2014 05:33
Pagination for CPTs
<?php // Pagination ?>
<?php
$big = 999999999;
$total = $kolfolio->max_num_pages;
$paginate = paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var( 'paged' ) ),
'prev_text' => __( '&larr; Previous', 'kol' ),
@alexmangini
alexmangini / gist:9752459
Created March 25, 2014 00:29
A basic content switcher script. Can be used for multiple tabbed content on a page.
jQuery('.js-tab-link a').click(function(){
var that = jQuery(this);
var tabIndex = that.parent().index();
var tabs = that.parents('.gallery-item').find('.gallery-cover-content');
that.parent('.js-tab-link').siblings().removeClass('gallery-active');
that.parent('.js-tab-link').addClass('gallery-active');
tabs.removeClass('gallery-active');
tabs.eq(tabIndex).addClass('gallery-active');