White Mope’s web things blog

WELCOME TO OUR BLOG. White Mope (www whitemope.com) is three-strong web design firm based in Sydney, Australia. As we learn stupid little tricks that make the internet work, we’ll post them here, for us to archive and for you to discover via some wild Google search. We’ll try to avoid extended geek-ham explanations and patronising tutorials, just stick up some shotgun fixes for css, html, wordpress, php, drupal, etc etc… whatever we’ve discovered by accident or otherwise. We’ll also put up a Paypal donation link in due course.

Display the Post or Page slug in a WordPress theme template

It’s crazy that you have to add this function in yourself. But… you do.

Firstly open up functions.php and paste the following in anywhere, like, ahh, at the very bottom:

function the_slug() {
$post_data = get_post($post->ID, ARRAY_A);
$slug = $post_data['post_name'];
return $slug; }

And now, in your template, display the slug thus:

<?php echo the_slug(); ?>

Tschuss!

Remove ugly Skype reformatting for phone numbers on your site

If you’re a typography nark then you might have encountered this issue when building your meticulous design. Is your local installation of Skype reformatting the phone numbers on your website? Does it make it look real bad? Do you not care that people might miss out on the click-to-call functionality? I don’t!

The trick is to make Skype not recognise the string as a phone number. And you can do this by shoving some hidden text in the middle of it.

So this:

<p>+12 (3) 4567 8910</p>

can become this:

<p>+12 (3) 4567<span style="display:none">get lost, Skype</span> 8910</p>

…and Skype will pipe down. Work-arounds kick!

Redirect your site for mobile devices, in particular iPhone, iPod and iPad

This isn’t exactly an elusive solution to find all over the internet, but here it is regardless. Put these in your <head>. This first script is for generic mobile devices, redirecting to a folder I’ve called mobile:

<script type="text/javascript">
<!--
if (screen.width <= 699) {
document.location = "mobile";
}
//-->
</script>

And here is another which is specifically good for Apple devices:

<script language=javascript>
<!--
if ((navigator.userAgent.match(/iPhone/i)) 
|| (navigator.userAgent.match(/iPod/i))
|| (navigator.userAgent.match(/iPad/i))) {
   location.replace("http://www.yourdomain.com/mobile");
}
-->
</script>

Clipboard or print screen or ctr paste not working with Photoshop

Gaaaa this drove me crazy for like 2 years because I could never work out what the actual problem was. And being so erratic, it was never worth tracking down. In short… if you ever have an issue where you hit PrintScreen or Image>Copy from a browser or somewhere, and then try and Paste into Photoshop, and it just doesn’t Paste, even though by fire-and-brimstone it worked fine just seconds ago, do this.

  1. Open a blank text file, in NotePad or TextEdit, etc
  2. Paste in the following…
    Windows Registry Editor Version 5.00
    [HKEY_CURRENT_USER\Software\Adobe\Photoshop\10.0]
    “AlwaysImportClipboard”=dword:00000001n
  3. Save the file as AlwaysImportClipbd_ON.reg
  4. Close file, close Photoshop, then run the file by double-clicking the bastard, accepting all breeches of Win7 or Vista security that ensue
Open up Photoshop again and voila, the designated PS clipboard should stop causing you trouble. That worked for my setup, which is CS4 on Windows 7 64bit, and it should work for you too, hopefully.

The correct way to style hyperlinks / a tags in CSS

CSS best practices… here’s how to style a hyperlink properly, states accounted for, ordered correctly. Do this when you’re just starting out on your CSS file save annoying nigglies down the track.

a:link {blah:blah;}
a:visited {blah:blah;}
:link:hover, :visited:hover {blah:blah;}
:link:active, :visited:active {blah:blah;}

Display a Google Map in a hidden div, in a Drupal 6 node template, given values from CCK Location inside a CCK Multigroup

This was a real gnarly one. So I’m not going to describe the problem – I figure if you got here via Google, then you have a similar setup sequence as in the title of this post, and subsequently you’ll be hurting real bad and willing to look at any freakn’ code. CCK Multigroup for Drupal 6 is one of the jankiest modules out there, yet it’s applications are so useful. Team that up with the equally janky Location module, and… kill me.

Anyway, enough said, here’s some script:

<?php $result = db_query('SELECT city, latitude, longitude FROM {location} WHERE lid = %d', $_GET['location']);
         $festcity = db_fetch_object($result);
         $city = $festcity->city;
         $latm1 = $festcity->latitude;
         $lonm1 = $festcity->longitude; ?>
<script type="text/javascript">
    $(function() {
        var latlng = new google.maps.LatLng(<?php echo $latm1; ?> , <?php echo $lonm1; ?> );
        var myOptions = {
            zoom: 8,
            center: latlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        }
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    var marker = new google.maps.Marker({
            position: latlng,
            map: map,
            title: "<?php echo $city; ?>"
        });
    })
</script>

 

And look here’s some more, thanks Googlemaps:

<script type="text/javascript">
    var map;
    var global_markers = [];
       <?php
            $markers = array();
        foreach ($node->field_location as $location) {
            $lat = $location['latitude'];
            $lon = $location['longitude'];
            $city = $location['city'];
            $markers[] = "[$lat , $lon , '$city']";
        }
            $strMarkers = "[";
            foreach($markers as $marker) {
            $strMarkers .= $marker. ',';
            }
            $strMarkers .= "]";
     print "var markers = $strMarkers;";
        ?>
function initialize() {
    var latlng = new google.maps.LatLng(-34.397, 150.644);
    var myOptions = {
        zoom: 3,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    addMarker();
  }

function addMarker() {
    for (var i = 0; i < markers.length; i++) {
        // obtain the attribues of each marker
        var lat = parseFloat(markers[i][0]);
        var lng = parseFloat(markers[i][1]);
        var trailhead_name = markers[i][2];

        var myLatlng = new google.maps.LatLng(lat, lng);

        var marker = new google.maps.Marker({
            position: myLatlng,
            map: map,
            title: trailhead_name
        });

    }
}
        var infowindow = new google.maps.InfoWindow({});
</script>

 

And now, ladies and gentlemen, you can display a Google Map marking your co-ordinates of multiple locations, inside a div where display:none, and when display:block, it will work like a dream, thus:

<div style="display:none">
<div id='map_canvas' style='width:622px; height:280px; margin:15px 0 30px 0;'></div>
</div>

 

If anyone wants to reverse-engineer this, explain it, and even better it (I know it’s very possible to do so) be my guest.

Give Facebook a standard image from your site to display on streams

When publishing a web page URL in a Facebook status, FB magic will try to identify an image to thumb up with the post. The image / images it finds are often totally irrelevant, pulling from a widget or an ad or something else on your page.  Sometimes, for whatever reason, it doesn’t actually offer the hero image as a selection. To give Facebook a specifically formatted, standard image or logo to offer first to users when they put your web page in their status, just put this in your page/s head:

<link rel="image_src" href="/images/blog-thumbnail.png" />

That little rel value is what Facebook is looking for. The rest is your image somewhere on your server.

jQuery show/hide div causing page to clunk when scroll-bars are activated

For our first post I’ll start with one of my recent favorite quick-fixes. I had a very simple site that was displaying content by showing and hiding blocks using jQuery. The problem was, when there was lots of content being revealed, the browser’s vertical scroll bar was activated, and vice versa. This caused the page content to “clunk” sideways, and that, in turn, was making me annoyed.

Fix… permanently activate the scroll bar using CSS:

body {
margin-bottom: 1px;
height: 101%;
}

Bang. Both attributes are required for it to work in both Firefox and Chrome, don’t ask me why.