Archive for category Web design & development
Dynamically create a PHP variable name
Posted by admin in Web design & development on June 29, 2012
Thanks to this post “Dynamic variable names in PHP” for enlightening me on how easy this is. There’s a lot of stuff out there about PHP variable variables but if you just want to craft a variable’s name based on some other variables that are already set – this is the way to go.
$var = "FooBar";
$extended_FooBar = "</pre>
<h2>An Extension of FooBar</h2>
<pre>
";
echo ${"extended_{$var}"} ;
Basically a regular variable with lots of curly braces and – in this case – not a dot concatenation operator in sight.
So simple when you know how.
Remove and ignore dreamweaver dwsync.xml files from your GIT repo
Posted by admin in Web design & development on August 30, 2011
git ignore dreamweaver dwsync.xml files (and other gubbins as required)
-
Remove any files already added form the working directory. For example:
$ git rm -f *dwsync.xml -
set up your a global git ignore file
create a gitignore file in your home directory. eg:
$ printf "dwsync.xml\nThumbs.db\n" >> ~/.gitignoreusing git config add this to you git prefs
$ git config --global core.excludesfile ~/.gitignore
For repos that may be worked on by multiple users you should also create this file at the root of your working directory.
References
hcodep://jqr.github.com/2009/02/03/global-git-ignore.html
hcodep://help.github.com/ignore-files/
Hard coding your site URL in WordPress
Posted by admin in Web design & development on July 29, 2011
I discovered this handy feature on troubleshooting a login problem for a client of mine.
If you swap your WP database between a development and production server at all regularly and don’t fancy editing your site URL and WordPress URL in the wp-options table each time (either directly or via the WP admin interface)… you can hard code it into the wp-config.php file! Tie this together with WordPress ability to keep this config file out of harms way in a directory above your WP install (ie out of your public_html directory) and you have an easy hands free file sync operation too.
Just add these two lines of code into wp-config.php:
// hardcoding the domain
define("WP_SITEURL","http://www.mysite.com");
define("WP_HOME","http://www.mysite.com");
BTW – note the lack of trailing slashes on the URLs
Nice WordPress article in .Net
Posted by admin in Web design & development on July 25, 2011
Nice article about WordPress in my favourite web design and develpment magazine (issue 217 of .NET). Usual stuff but well written without either speeding or jabbering.
There’s a nice overview of Custom Menus, Multisite, Custom Post Formats, Custom Post types and Custom Taxonomies.
WP Custom Heaven
One thing I’d never heard of before was the new ability in WordPress 3.x to enable custom background images to any post. Just add the following to your functions.php file:
add_custom_background();
. Look up the codex for more. Aparently this allows admin users to change background image properties (as CSS) from within the appearance menu. http://codex.wordpress.org/Function_Reference/add_custom_background. Having not tried this – but I think its limited to a global preference per install – so of limited use to theme developers.
Anyway nice stuff Jeff Starr at .Net …
PHP 101. Basic stuff: get value from URL querystring with PHP
Posted by admin in Web design & development on July 11, 2011
As I’m still an idiot when it comes to media queries and mobile devices and can pass this stuff on to other folks – but needed to give myself and the interested parties a visual representation of how different sized graphics will be delivered to different mobile devices… I was after a simple ‘switch’ that would allow a single wedge of HTML to render according to a variable.
The example here goes along the lines of http://example.com?width=340 where the width has a few values it accepts or will default to a preset size…
This variable can then get passed around in the PHP file to set image dimaensions CSS etc…
<?php
function getUrlStringValue($urlStringName, $returnIfNotSet) { if(isset($_GET[$urlStringName]) && $_GET[$urlStringName] != "") return $_GET[$urlStringName]; else return $returnIfNotSet; }
$width = getUrlStringValue("width", "480");
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<head><title></title><meta name="viewport" content="width=<?php echo $width ;?>" />
JavaScript redirect based on referrer
Posted by admin in Web design & development on June 21, 2011
Basic stuff (as often the case not immediately findable). You want a simple script to redirect to a different page if te referrer is such and such. In the following example the two referral page options ( foo.html and bar.html ) are separated with the double pipe (the ‘or’ bit)…
<script type="text/javascript">
if (document.referrer == ("http://example.com/foo.html" || "http://example.com/bar.html"))
location.href = "foobar.html";
</script>
CSS 3 pseudo-classes and attribute selectors in Internet Explorer
Posted by admin in Web design & development on May 27, 2011
Thanks to my mate Tony I’ve been introduced to this rather delicious (and very small) jQuery plugin that adds support for, among other things the :nth-child pseudo class. If this had been around a year ago ‘d have avoided having to craft this php counting system for a custom WordPress loop.
What’s the link already?
Here you go Jack: Selctivizr
Shout out to our kid Tony and good luck to him and his latest baby – an online platform for Illustrators: the artfuls