Jan 5, 2012 - WordPress    Comments Off on Conditional CSS for IE

Conditional CSS for IE

wp_enqueue_style(
   'ie7-style',
   get_template_directory_uri() . '/ie7.css'
);
global $wp_styles;
$wp_styles->add_data( 'ie7-style', 'conditional', 'lte IE 7' );
Jan 4, 2012 - PHP    Comments Off on Test a Form Entry Against a CSV File.

Test a Form Entry Against a CSV File.

The simple way.

<?php
/**
* Test for post; check against list; return error if bad.
*/
function check_data($input){
	//if the input is null, go no further;
	if(empty($input))
		return 'Please enter a valid code.';
	//if the input isn't 6 alphanumeric characters, go no further
	if(!preg_match('/[A-Za-z0-9]{6}/i',$input))
		return 'The code provided is not valid.';
	//finally, test against the list
	$filepath = dirname(__FILE__).'/data/datafile.csv';
	if (($list = fopen($filepath, "r")) !== FALSE) {
		while (($data = fgetcsv($list, 1000, ',')) !== FALSE) {
			if($input == $data[0]){
				header('Location:'.$data[1]);
				die();
			}
		}
		fclose($list);
	}
	return 'The code provided is not valid.';
	}
if($_POST)	
$error = check_data($_POST['code']);
?>
Jan 3, 2012 - PHP    Comments Off on Splash Page Cookie function

Splash Page Cookie function

function cookie_jumper($cookie_name, $redirect = '', $exp = 86400){
	$mycookie = $_COOKIE[$cookie_name]!='' ? $_COOKIE[$cookie_name] : FALSE;
	$exp = time() + $exp;
	if($mycookie){
		header('Location:'.get_site_url().$redirect);
	} else {
		setcookie($cookie_name,TRUE,$exp);
	}
}
Dec 26, 2011 - WordPress    Comments Off on Default to no link on images

Default to no link on images

This goes into the functions.php file or similar:

//remove auto-links on media
update_option('image_default_link_type','none');
Dec 26, 2011 - PHP    Comments Off on Display stuff inline for troubleshooting

Display stuff inline for troubleshooting

<?php
/*
* A useful troubleshooting function. Displays arrays in an easy to follow format in a textarea.
*/
if ( ! function_exists( 'ts_data' ) ) :
function ts_data($data){
	$ret = '<textarea class="troubleshoot" cols="100" rows="20">';
	$ret .= print_r($data,true);
	$ret .= '</textarea>';
	print $ret;
}
endif;
/*
* A useful troubleshooting function. Dumps variable info in an easy to follow format in a textarea.
*/
if ( ! function_exists( 'ts_var' ) && function_exists( 'ts_data' ) ) :
function ts_var($var){
	ts_data(var_export( $var , true ));
}
endif;
Dec 26, 2011 - Genesis    Comments Off on Genesis Post Image

Genesis Post Image

Default only works on certain pages/posts:

add_action('genesis_post_content', 'genesis_do_post_image');
/**
* Post Image
*/
function genesis_do_post_image() {
if ( !is_singular() && genesis_get_option('content_archive_thumbnail') ) {
$img = genesis_get_image( array( 'format' => 'html', 'size' => genesis_get_option('image_size'), 'attr' => array( 'class' => 'alignleft post-image' ) ) );
printf( '%s', get_permalink(), the_title_attribute('echo=0'), $img );
}

}

Here’s a sample fix:

remove_action( 'genesis_post_content','genesis_do_post_image');
add_action( 'genesis_before_post_content','tapestry_do_post_image');</code>

function tapestry_do_post_image() {
$img = genesis_get_image( array( 'format' =&gt; 'html', 'size' =&gt; genesis_get_option('image_size'), 'attr' =&gt; array( 'class' =&gt; 'aligncenter post-image' ) ) );
printf( '<a title="%s" href="%s">%s</a>
<div class="clear"></div>
', get_permalink(), the_title_attribute('echo=0'), $img );
}
Pages:«12345678