Browsing "WordPress"
Aug 8, 2012 - Javascript, WordPress    Comments Off on more on single page/post JS

more on single page/post JS

http://scribu.net/wordpress/optimal-script-loading.html

class My_Shortcode {
	static $add_script;

	static function init() {
		add_shortcode('myshortcode', array(__CLASS__, 'handle_shortcode'));

		add_action('init', array(__CLASS__, 'register_script'));
		add_action('wp_footer', array(__CLASS__, 'print_script'));
	}

	static function handle_shortcode($atts) {
		self::$add_script = true;

		// actual shortcode handling here
	}

	static function register_script() {
		wp_register_script('my-script', plugins_url('my-script.js', __FILE__), array('jquery'), '1.0', true);
	}

	static function print_script() {
		if ( ! self::$add_script )
			return;

		wp_print_scripts('my-script');
	}
}

My_Shortcode::init();
Jul 30, 2012 - WordPress    Comments Off on Sneaky OrderBy stuff.

Sneaky OrderBy stuff.

When ordering a query by meta_value, if you are using a numeric meta_value, do this:

$args = array( 
	'post_type' => 'msd_contest_entry', 
	'numberposts' => -1, 
	'meta_key' => 'Votes',
	'orderby' => 'meta_value_num'
	);
$items = get_posts($args);

Otherwise:

$args = array( 
	'post_type' => 'msd_contest_entry', 
	'numberposts' => -1, 
	'meta_key' => 'Votes',
	'orderby' => 'meta_value'
	);
$items = get_posts($args);
Jun 25, 2012 - Javascript, WordPress    Comments Off on Javascript on just ONE Admin Page

Javascript on just ONE Admin Page

I ran into this issue recently when I had a setting page that allowed a file upload (image for logo) and the script for it started overriding the general image uploader across the entire admin. Grrf. A better way to hook the .js is found on Justin Tadlock’s blog. (I wasn’t able to do this exactly, but I used the idea.)

add_action( 'admin_menu', 'my_example_settings_page' );

function my_example_settings_page() {
	global $my_settings_page;

	$my_settings_page = add_options_page( 'DevPress Example', 'DevPress Example', 'manage_options', 'my-example-page-name', 'my_callback_function' );

	add_action( 'admin_enqueue_scripts', 'my_admin_enqueue_scripts' );
}

function my_admin_enqueue_scripts( $hook_suffix ) {
	global $my_settings_page;

	if ( $my_settings_page == $hook_suffix )
		wp_enqueue_script( 'my-example' );
}
Jun 5, 2012 - WordPress    Comments Off on Widgets Style

Widgets Style

Plugin idea: a plugin to add the ability to wrap any widget with a class. Would be great for the custom styled widgets like Cole likes.

Update: http://wordpress.org/extend/plugins/zigwidgetclass/ Perfect.

May 31, 2012 - WordPress    Comments Off on Clean up WordPress revisions

Clean up WordPress revisions

Salut,

Ce n’est pas suffisant, il y a deux autres tables affectees par l’autosave (wp_term_relationships et wp_postmeta), le code complet serait:

delete x,y,z
from wp_posts x
left join wp_term_relationships y on (x.id = y.object_id)
left join wp_postmeta z on (x.id = z.post_id)
where x.post_type = 'revision'

 

found in the comments over here

Apr 13, 2012 - Genesis    Comments Off on Adding Meta to the Theme Stettings

Adding Meta to the Theme Stettings

Something changed in 1.8+ and the old hook no longer works. To make the hook work again, and keep things backwards compatible, try something like this:

add_action( 'admin_menu', 'childtheme_add_footer_tag_settings_box', 11 );
/**
 * Add new box to the Genesis->Theme Settings page.
 *
 */
function childtheme_add_footer_tag_settings_box() {
	global $_genesis_theme_settings_pagehook;
	if(!$_genesis_theme_settings_pagehook){
		$_genesis_theme_settings_pagehook = 'toplevel_page_genesis';
	}
	add_meta_box( 'genesis-theme-settings-style', __( 'Meta Box title', 'childtheme' ), 'childtheme_theme_settings_footer_tag_box', $_genesis_theme_settings_pagehook, 'column2' );
}
Mar 22, 2012 - Mobile, WordPress    Comments Off on Responsive design: adding scripts and styles

Responsive design: adding scripts and styles

add_action('wp_print_scripts', 'themename_add_scripts');
 
function themename_add_scripts() {
	if(!is_admin()){
    	wp_enqueue_script('theme_jquery', get_bloginfo('template_url').'/js/theme-jquery.js', array('jquery'),NULL,TRUE); 
    	if(is_front_page()){
    		wp_enqueue_script('homepage_jquery', get_bloginfo('template_url').'/js/homepage-jquery.js', array('jquery'),NULL,TRUE);    
    	}
       	if(is_mobile()){
       		//change some content with jQuery
       		wp_enqueue_script('mobile_jquery', get_bloginfo('template_url').'/js/mobile-jquery.js', array('jquery'),NULL,TRUE); 
       		//add support for older iphones
			$agent = $_SERVER['HTTP_USER_AGENT'];
			$version = preg_match('/OS\s([\d+_?]*)\slike/i', $agent, $matches);
			$version = str_replace('_', '.', $matches[1]);
			if (!(preg_match('/ip(hone|ad|od)/i', $agent)) || ((preg_match('/ip(hone|ad|od)/i', $agent) && $version < 5))) {
				wp_enqueue_script('ios4_jquery', get_bloginfo('template_url').'/js/ios4-jquery.js', array('jquery'),NULL,TRUE); 
			}
       	}
	}
}
add_action('wp_print_styles', 'themename_add_styles');
 
function themename_add_styles() {
    if(!is_admin()){
        wp_enqueue_style('desktop', get_stylesheet_directory_uri().'/css/960.css', NULL, NULL, 'screen and (min-width: 769px)');   
        wp_enqueue_style('ipad', get_stylesheet_directory_uri().'/css/ipad.css', NULL, NULL, 'only screen and (min-device-width : 768px) and (max-device-width : 1024px)');           
        wp_enqueue_style('mobile', get_stylesheet_directory_uri().'/css/mobile.css', NULL, NULL, 'only screen and (max-width: 768px)');     
    }
}
Mar 22, 2012 - WordPress    Comments Off on Adding theme scripts

Adding theme scripts

add_action('wp_print_scripts', 'themename_add_scripts');
 
function themename_add_scripts() {
	if(!is_admin()){
    	wp_enqueue_script('theme_jquery', get_stylesheet_directory_uri().'/js/theme-jquery.js', array('jquery'),NULL,TRUE);    
    	if(is_front_page()){
    		wp_enqueue_script('homepage_jquery', get_stylesheet_directory_uri().'/js/homepage-jquery.js', array('jquery'),NULL,TRUE);    
    	}
	}
}

Feb 3, 2012 - WordPress    Comments Off on Those wacky theme paths

Those wacky theme paths

  • get_template_directory(): Returns the absolute template directory path. (PARENT)
  • get_template_directory_uri(): Returns the template directory URI.
  • get_stylesheet_directory(): Returns the absolute stylesheet directory path. (CHILD)
  • get_stylesheet_directory_uri(): Returns the stylesheet directory URI.

See also: How To Load Files Within WordPress Themes

Pages:«12345»