Passing a variable about in a WordPress theme

I’m used to using php variables set in included  file being used in another included file if all are included in the same document. This doesn’t work in WordPress theme parts. It’s easy to overcome though… you just need to recall the variable first…

somewhere in functions.php

 $my_var = "xyz" 

Now i can do this somewhere in header.php

<?php global $myVar ;  ?>
<?php echo $myVar; ?>

,

No Comments

Multiple WordPress excerpt lengths

Q. Got a theme that needs two different excerpt lengths?

A. Found here: set the standard, longer excerpt as normal in the functions.php file and the override locally using this code:

<?php echo substr( get_the_excerpt(), 0, strrpos( substr( get_the_excerpt(), 0, 75), ' ' ) ); ?>

 

,

No Comments

Rollback a GIT commit

GIT is great, Git is good.

I mostly use git to track changes (very useful to check on what I’ve  been up to when it’s late in the night!) but occasionally I need to use it to roll back to a previous commit. This is the command I always forget, and today it took me more than one minute to find the answer (or formulate the right question) on google.

The answer, unsurprisingly on stackoverflow: in your [git tracked] working directory enter this terminal command:

git reset --hard <tag/branch/commit id>

Where  you replace the gubbins inside the angle brackets with the SHA ID of your commit. Find this easily using GitX or my potential new favourite GIT client on the Mac: Gitti.

No Comments

Using GIT to manage a website…

Nice little write-up on pushing your local GIT repo to a live web site: http://toroid.org/ams/git-website-howto

No Comments

Magazine framework in Javascript

treesaverjs.com/

Incredible, clever, simple looking demo: http://demo.nomadeditions.com/real-eats/index.html

,

No Comments

MySQL Command Line stopped working in Mac OS 10.6?

Do what this guy says and add <tt>/usr/local/mysql/bin</tt> back into your paths file

No Comments

Turn a text list into an HTML Select Option list with PHP

Easy solution to this basic HTML coding need posted over at Stack Overflow by a random clever bloke. Thanks RCB.

<?php

  $fc = file_get_contents('./test.txt');
  $fc = utf8_encode ( $fc );
	$lines = explode("\n", $fc);

  $html = '<select>';
  foreach($lines as $line)
     $html .= '<option value="' . $line . '">' . $line . '</option>';

  $html .= '</select>';
  echo $html;
?>

My only issue was with UTF-8 characters coming through garbled. Bodged a workaround using this encode entities plug-in for Dreamweaver.

,

No Comments