Passing a variable about in a WordPress theme
Posted by admin in Web design & development on April 28, 2011
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; ?>
Multiple WordPress excerpt lengths
Posted by admin in Web design & development on April 28, 2011
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), ' ' ) ); ?>
Rollback a GIT commit
Posted by admin in Web design & development on April 28, 2011
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.
Using GIT to manage a website…
Posted by admin in Asides, Web design & development on February 21, 2011
Nice little write-up on pushing your local GIT repo to a live web site: http://toroid.org/ams/git-website-howto
Magazine framework in Javascript
Posted by admin in Asides, Web design & development on February 21, 2011
Incredible, clever, simple looking demo: http://demo.nomadeditions.com/real-eats/index.html
MySQL Command Line stopped working in Mac OS 10.6?
Posted by admin in Asides, Web design & development on February 16, 2011
Do what this guy says and add <tt>/usr/local/mysql/bin</tt> back into your paths file
Turn a text list into an HTML Select Option list with PHP
Posted by admin in Asides, Web design & development on February 3, 2011
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.