Skip to content

Instantly share code, notes, and snippets.

View senlin's full-sized avatar

Pieter Bos senlin

View GitHub Profile
@senlin
senlin / loop-posttype.php
Created August 18, 2012 06:44
sample code to implement ContentFlow.js in WordPress
<?php
// the following will be part of your loop.
?>
<div class="ContentFlow">
<div class="flow">
<?php
$asliders = query_posts('post_type=artist&posts_per_page=-1');
if ($asliders) {
foreach ($asliders as $aslider) {
// my original code included a checkbox custom metabox "_artist_slider", the code below calls these metadat and checks whether this box has been ticked ("on"). If your site doesn't use any metaboxes to condtionally show the post in the slider, then you need to delete the "if ($meta == 'on')" condition.
@senlin
senlin / page-testimonials.php
Created November 30, 2012 01:49
Testimonials Page Example
<?php
/** Template Name: Testimonials */
get_header(); ?>
<div class="page-header">
<h1 class="page-title">
<?php _e( 'Testimonials', 'basejump' ); ?>
</h1>
</div><!-- end .page-header -->
<div <?php post_class(); ?>>
@senlin
senlin / Contract Killer 3.md
Last active October 13, 2015 15:37 — forked from malarkey/Contract Killer 3.md
The latest version of my ‘killer contract’ for web designers and developers

Contract Killer 3

Revised date: 07/11/2012

Between us [company name] and you [customer name]

Summary:

We’ll always do our best to fulfil your needs and meet your expectations, but it’s important to have things written down so that we both know what’s what, who should do what and when, and what will happen if something goes wrong. In this contract you won’t find any complicated legal terms or long passages of unreadable text. We’ve no desire to trick you into signing something that you might later regret. What we do want is what’s best for both parties, now and in the future.

@senlin
senlin / highlighting-wp_nav_menu-ancestor-children-custom-post-types.php
Created December 27, 2012 13:08
Highlight the wp_nav_menu menu item when on a Custom Post Type.
<?php
// The code below finds the menu item with the class "[CPT]-menu-item" and adds another “current_page_parent” class to it.
// Furthermore, it removes the “current_page_parent” from the blog menu item, if this is present.
// Via http://vayu.dk/highlighting-wp_nav_menu-ancestor-children-custom-post-types/
add_filter('nav_menu_css_class', 'current_type_nav_class', 10, 2);
function current_type_nav_class($classes, $item) {
// Get post_type for this post
$post_type = get_query_var('post_type');
@senlin
senlin / remove-welcome-panel.php
Last active December 10, 2015 16:29
In 3.5+, this hook allows you disable the Welcome Panel in the Dashboard. Removing the action also removes the corresponding Screen Option. source: http://codex.wordpress.org/Plugin_API/Action_Reference/welcome_panel
<?php
// In 3.5+, this hook allows you disable the Welcome Panel in the Dashboard.
// Removing the action also removes the corresponding Screen Option.
// source: http://codex.wordpress.org/Plugin_API/Action_Reference/welcome_panel
remove_action( 'welcome_panel', 'wp_welcome_panel' ); ?>
<?php
add_theme_support('menus');
/*
http://codex.wordpress.org/Function_Reference/register_nav_menus#Examples
*/
register_nav_menus( array(
'main-menu' => 'Main Menu' // registers the menu in the WordPress admin menu editor
) );
<?php
add_action('init', 'wptips_custom_init');
function wptips_custom_init() {
add_post_type_support( 'portfolio', array( 'page-attributes', 'comments', 'author' ) );
}
?>
@senlin
senlin / episodes-feed.php
Last active December 17, 2015 20:29
Get last 5 episodes to show if "rss" custom field has been filled in. If not, output other message. See Google+ https://plus.google.com/u/0/116025569345227867532/posts/GcWYWECU7pd
<?php // Google+ post https://plus.google.com/u/0/116025569345227867532/posts/GcWYWECU7pd
include_once(ABSPATH.WPINC.'/feed.php');
{
$grss=get_post_meta($post->ID, 'rss', true);
$rss = fetch_feed($grss);
if (!is_wp_error($rss)) { // Checks that the object is created correctly
$maxitems = $rss->get_item_quantity(5);
$rss_items = $rss->get_items(0, $maxitems);
}
@senlin
senlin / index.php
Created March 6, 2014 00:25
Custom controls in the theme customizer using WP_Query() instead of query_posts(). Article on http://code.tutsplus.com/articles/custom-controls-in-the-theme-customizer
<div id="posts">
<?php
// Get category ID from Theme Customizer
$catID = get_theme_mod( 'tcx_category' );
// Only get Posts that are assigned to the given category ID
$args = array(
'post_type' => 'post',
'cat' => $catID
);
@senlin
senlin / slippry-slider-sample.php
Created April 8, 2014 13:37
sample to build slider with featured image with slippry
<?php
/**
* The following code is a copy of the code I recently used on the site of a client
* It uses the Aqua-Resizer script (https://github.com/syamilmj/Aqua-Resizer) to
* dynamically resize the slider images to the size needed.
*
* @source Piet Bos http://senlinonline.com
*/
echo '<div class="slider-wrapper">';