Adding this to your template file or functions.php in some cases will allow your PHP scripts to access variables passed in the URL query strings.  You know, that ugly text after the Question mark in the website address:  “http://tools.belchamber.us?variable=value&variable2=value”.  Most of you probably already figured out just looking at these type of URLs that some values are being passed from one page to another.  The variables extracted this way are called “Get variables” and aren’t very secure.

Remember to avoid passing any sensitive or personal data inside a URL — anyone can view it on the address bar, or worse yet – in your browser history!


function add_query_vars_filter( $vars ){

$vars= array("var1","var2","var3");

return $vars;

}

add_filter( 'query_vars', 'add_query_vars_filter' );


There are some new CSS tricks coming out that will allow for this to be done natively, but until then, here’s a way to make sure that all elements in a page, say gallery thumbnails or excerpts from posts, all display their full texts and are all sized the same.  Without using this fix after page load, some elements may display taller than others, and if these elements are floating in the page, they may definitely not display in a nice even grid as intended.same-height-of-elements-in-pageWith a few lines of jQuery (make sure you load the newest version via CDN) you just simply assign the elements you want to have the same height with the same unique class, like “same-height-group-1” or something short you can remember.  Then, change out the “.class-to-resize” in the script below with the actual class you assigned the elements.  From now on, after a page loads, all the elements assigned that same class will all have the same height, and you will never have to worry about those “sticky” floating blocks that ruin the whole look of your page.


<script type="text/javascript">
// You might probably want to envelope the below in a $(document).ready() function

max_h=0;

$(".class-to-resize").each(function(){

this_h=$(this).height();
if (this_h>max_h) { max_h=this_h;}

});

// Now, cycle through again to resize all elements to the maximum height

if (max_h>0){
$(".class-to-resize").each(function(){

$(this).height(max_h);

});

}

</script>


So simple, but yet, so under used.  Force the browser to reload the page’s contents without loading anything from its temporary cache.

What the heck does “pragma” mean?  Let’s be pragmatic and find out!


<meta http-equiv="pragma" content="no-cache" />


RSS feeds are handy, but let’s face it, images do say so much more than words.  They stand out and grab attention, they help people identify blocks of information quicker.  They really are worth 1,000 words if you think about it.  Sometimes, a lot more….

Add this to your template or into your functions.php file:


function rss_post_thumbnail($content) {
global $post;
if(has_post_thumbnail($post->ID)) {
$content = '<p>' . get_the_post_thumbnail($post->ID) .
'</p>' . get_the_content();
}
return $content;
}
add_filter('the_excerpt_rss', 'rss_post_thumbnail');
add_filter('the_content_feed', 'rss_post_thumbnail');


Moving from procedural with mysql_connect, etc to PDO objects should be an easy transition.  It’s so much faster and reliable, too.  The “mysql” library in PHP will soon be deprecated, so you hold-outs won’t have a choice.  It’s actually less code to write and get whole queries into resulting arrays much faster.  Trust me!

Here’s how you instance a new PDO object and connect to your MySQL database through PDO:


<?php

/*** mysql hostname ***/
$hostname = 'localhost';

/*** mysql username ***/
$username = 'username';

/*** mysql password ***/
$password = 'password';

try {
$dbh = new PDO("mysql:host=$hostname;dbname=mysql", $username, $password);
/*** echo a message saying we have connected ***/
echo 'Connected to database';
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>