Skip to content

Instantly share code, notes, and snippets.

View roose's full-sized avatar
🐢
Looking for a job

roose roose

🐢
Looking for a job
View GitHub Profile
@felipelavinz
felipelavinz / functions.php
Created November 9, 2010 20:38
A basic WordPress functions.php as starting point for theme development
<?php
/* Register WordPress theme settings ******************************************/
/* Navigation menus -----------------*/
register_nav_menus( array(
'primary' => 'Principal'
));
/* Images ---------------------------*/
add_theme_support( 'post-thumbnails' );
/* Sidebars -------------------------*/
@jhaus
jhaus / SimplestWidget_Widget.php
Created November 26, 2010 03:47 — forked from straps/SimplestWidget_Widget.php
Abstract class to create easily wordpress widgets, documented here http://www.strx.it/2010/11/wordpress-widgets-template/
<?php
class SimplestWidget_Widget extends Strx_Widget {
function w_id(){ return 'simplest-widget'; }
function w_name(){ return 'My Simplest Widget'; }
/** Return the dashboard admin form */
function w_form($instance){
return '<p>'.$this->w_form_input($instance, 'title').'</p>';
}
@jhaus
jhaus / cpt-search.php
Created November 29, 2010 23:58
search wp custom post types too
<?php
// hook into wordpress search function
add_filter( 'the_search_query', 'aggregated_search' );// Define what post types to search
function aggregated_search( $query ) {
if( $query->is_search ) {
$query->set( 'post_type', array( 'post', 'page', 'feed', 'attachment', 'movies', 'quotes' ));//define search types
}
return $query;
}
<?php
// Initialize the Class and add the action
add_action('init', 'pTypesInit');
function pTypesInit() {
global $sites;
$sites = new TypeSites();
}
// Create a post type class for 'Site' posts
// To use as a bookmarking post type for sites you want to save/share.
@jhaus
jhaus / cpt-class-create.php
Created November 29, 2010 23:59
Class for creating custom post types, taxonomies and meta boxes via: http://new2wp.com/pro/wordpress-custom-post-types-object-oriented-series2
<?php
// Create a post type class for site posts
// To use as a bookmarking post type for sites you want to save/share.
class TypeSites {
public $meta_fields = array( 'title', 'description', 'siteurl', 'category', 'post_tags' );
public function TypeSites() {
$siteArgs = array(
'labels' => array(
<?php
$q = new WP_query();
$q->query( 'post_type=site' );
/* Begin the Loop */
if ($q->have_posts()) :
while ($q->have_posts()) : $q->the_post();
/**
* Now instantiate the Sites class we made in posttypes.php setting the $s variable
@jhaus
jhaus / default-wp-config.php
Created December 5, 2010 01:39
WP Config file with some useful default settings
<?php
/**
* The base configurations of the WordPress.
*
* This file has the following configurations: MySQL settings, Table Prefix,
* Secret Keys, WordPress Language, and ABSPATH. Get MySQL settings from web host.
* You can find more information by visiting the Codex page:
*
* @link http://codex.wordpress.org/Editing_wp-config.php
*
<?php
// ------------------------------------------------------------------
// Add all your sections, fields and settings during admin_init
// ------------------------------------------------------------------
//
function eg_settings_api_init() {
// Add the section to reading settings so we can add our fields to it
add_settings_section('eg_setting_section', 'Example settings section in reading', 'eg_setting_section_callback_function', 'reading');
<?php
class WordPress_Settings
{
/**
*
* @var array
*/
protected $_registry;
@jaredwilli
jaredwilli / gist:737092
Created December 11, 2010 02:18
Add Sorting to Custom Post types post manage page
add_action('restrict_manage_posts','restrict_manage_movie_sort_by_genre');
function restrict_manage_movie_sort_by_genre() {
if (isset($_GET['post_type'])) {
$post_type = $_GET['post_type'];
if (post_type_exists($post_type) && $post_type=='movie') {
global $wpdb;
$sql=<<<SQL
SELECT pm.meta_key FROM {$wpdb->postmeta} pm
INNER JOIN {$wpdb->posts} p ON p.ID=pm.post_id
WHERE p.post_type='movie' AND pm.meta_key='Genre'