Skip to content

Instantly share code, notes, and snippets.

View davemac's full-sized avatar

davemac davemac

View GitHub Profile
@davemac
davemac / gist:2357434
Created April 11, 2012 06:52
Show sticky posts in query
<?php $args = array(
'cat' => 4,
'posts_per_page' => 4,
'post__in' => get_option( 'sticky_posts' ),
);
$showNewsSticky = new WP_Query( $args );
while ($showNewsSticky->have_posts()) : $showNewsSticky->the_post(); ?>
<h2 class="small2 marginBottomQuater">
<a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
</h2>
@davemac
davemac / events-conditional-wrappers.php
Created July 19, 2012 12:07 — forked from jo-snips/events-conditional-wrappers.php
The Events Calendar: Basic Conditional Wrappers
if( tribe_is_month() && !is_tax() ) { // The Main Calendar Page
} elseif( tribe_is_month() && is_tax() ) { // Calendar Category Pages
} elseif( tribe_is_event() && !tribe_is_day() && !is_single() ) { // The Main Events List
} elseif( tribe_is_event() && is_single() ) { // Single Events
} elseif( tribe_is_day() ) { // Single Event Days
@davemac
davemac / gist:3410174
Created August 21, 2012 01:04
WP Remove unwanted dashboard items
// Remove unwanted dashboard items
add_action('wp_dashboard_setup', 'my_custom_dashboard_widgets');
function my_custom_dashboard_widgets() {
global $wp_meta_boxes;
//QuickPress
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
//Wordpress Development Blog Feed
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
@davemac
davemac / gist:3484845
Created August 27, 2012 01:13
Check if ACF fields exists
<?php elseif ( has_post_thumbnail() ) :
$featured_image_link = ( get_field( 'featured_image_links_to' ) );
if ( $featured_image_link ) {
echo '<a href="'.get_permalink($post_object->ID) .'">';
if ( has_post_thumbnail()) { the_post_thumbnail( 'hero-image-medium', array( 'class' => 'large fx' ) ); }
echo '</a>';
} else {
the_post_thumbnail( 'hero-image-medium', array( 'class' => 'large fx' ) );
};
endif; ?>
function get_deep_child_category( $categories )
{
$categories = get_the_category();
$maxId = 0;
$maxKey = 0;
foreach ( $categories as $key => $value )
{
if ( $value->parent > $maxId )
{
$maxId = $value->term_id;
@davemac
davemac / gist:3809674
Created October 1, 2012 05:42
WordPress remove old contact methods, add Twitter
// Remove obsolete user contact info and add new
function dmc_new_contactmethods( $contactmethods ) {
// Remove these
unset($contactmethods['aim']);
unset($contactmethods['yim']);
unset($contactmethods['jabber']);
// Add Twitter
$contactmethods['twitter'] = 'Twitter';
@davemac
davemac / gist:3855984
Created October 9, 2012 01:12
WordPress reverie_entry_meta revised
function reverie_entry_meta() {
$num_comments = get_comments_number();
$tags=get_the_tag_list(' ', ', ');
$output ='';
$output .= '<div class="entry-meta"><p>';
$output .= '<time class="updated" datetime="'. get_the_time('c') .'" pubdate>'. sprintf(__('%s'), get_the_time('jS F Y')) .'</time>, ';
// $output .= comments_number( 'No comments yet', '1 comment', '% comments' );
if ( comments_open() ) {
@davemac
davemac / gist:3862820
Created October 10, 2012 02:33
Display widget in template/theme
<?php the_widget('TribeEventsAdvancedListWidget', 'title=Upcoming Events',
(array(
'before_widget' => '<article id="%1$s" class="widget %2$s"><div class="sidebar-section">',
'after_widget' => '</div></article>',
'before_title' => '<h5>',
'after_title' => '</h5>'
))
); ?>
@davemac
davemac / gist:3957052
Created October 26, 2012 05:37
Hide plugins from certain WP users
function filter_visible_plugins($plugins) {
//Plugin file paths relative to /wp-content/plugins/
$pluginsToHide = array(
'akismet/akismet.php',
'hidden-plugin/hidden-plugin.php',
'another-plugin/filename.php',
);
//As an example, lets hide the above plugins from everyone
//except user 'smith'. Replace this with your own security checks.
@davemac
davemac / gist:3958298
Created October 26, 2012 11:33
Google Apps Script to split cells
function myFunction(){
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
//get the names from column B
var n = sheet.getRange('B:B').getValues();
var f = [];
for(var i=0; i<n.length; i++){
//Reformat each name and push it in array f
f.push(reformat(n[i][0]));
}
//Write back the reformatted name in Column C & D