Lee Powers Web Developer & Web Designer

Wordpress: get page template name

Posted by Lee Powers

Every Wordpress Page can have a page template as defined by the current Wordpress theme. Note that the page template and the Wordpress theme are two separate entities. A theme can define multiple page templates. Like so:

+ My Wordpress Theme
++ Default (page.php)
++ Full Page (page-full.php)
++ Home Page (page-home.php)

The page template is selected when editing a page in the Wordpress Admin. As in the following screen shot:

» Read more "Wordpress: get page template name"

jQuery Mobile maximum width

Posted by Lee Powers

jQuery mobile buttons, body text and form elements stretching out too wide on larger monitors? No problem! Drop in a few CSS rules to set a maximum width on the page.

Here's the full code with detailed explanation below:

» Read more "jQuery Mobile maximum width"

CSS override inline styles

Posted by Lee Powers

To override an inline CSS style use the !important modifier:

<p style="background-color: #f00; color: #fff">
Hello Redness
</p>
 
<p style="background-color: #f00; color: #fff" id="test">
Hello Blackness
</p>
 
<style type="text/css">
 #test {
  background-color: #000 !important;
 }
</style>

And here it is in action:

» Read more "CSS override inline styles"

jQuery animation callback called twice? (or more?) Use a promise()

Posted by Lee Powers

One of the more awesome recent features to jQuery has to be the promise() functionality. promise() enables detecting when a group of actions have all completed, regardless of queue status.

An example: animate a group of HTML elements using slideDown() but only trigger a callback once ALL the animations have completed. With the given HTML:

» Read more "jQuery animation callback called twice? (or more?) Use a promise()"

jQuery HTML5 data variables, data() and attr()

Posted by Lee Powers

A quick note on managing HTML5 data variables via .data() and .attr('data-name')

The .data() call is special - not only does it retrieve HTML5 data attributes it also attempts to evaluate/parse the attributes. So with an attribute like data-myjson='{"hello":"world"}' when retrieved via .data() will return a Javascript Object while retrieval via .attr() will return a string.

» Read more "jQuery HTML5 data variables, data() and attr()"

Javascript pass parameters or arguments to embedded script

Posted by Lee Powers

The goal: to parse arguments/parameters from within a Javascript embed script using the query string. So an embed script can be configured as follows:

<script src="embed.js?arg1=my+first+arg&amp;arg2=the+second+arg"></script>

This is ideal as you can load the embedded script configuration using pure Javascript and not require any server-side page to parse the querystring and dynamically generate the configured Javascript.

» Read more "Javascript pass parameters or arguments to embedded script"

You have already activated rake 0.8.7, but your Gemfile requires rake ....

Posted by Lee Powers

Ran into this rails error message while running a database migrate on a production site:

$ RAILS_ENV=production rake db:migrate
rake aborted!
You have already activated rake 0.8.7, but your Gemfile requires rake 0.9.2.2. Consider using bundle exec.

I tried a variety of fixes including this one but got a Don't know how to build task 'cron' error message in response to the attempted fix.

» Read more "You have already activated rake 0.8.7, but your Gemfile requires rake ...."

MySQL dump database to tar gz zipped file one-liner

Posted by Lee Powers

Quick one-liner for the command line for dumping a MySQL database to a gzipped file. There's no need to tar-ball it as we just want to compress a single dump file and tar is used for a group of files:

mysqldump powers1 -u root -p | gzip -c | cat > powers1-$(date +%Y-%m-%d-%H.%M.%S).sql.gz

Replace both instances of powers1 with the name of the database you want to dump. This one-liner will append the current date and time to the dump gz file.

» Read more "MySQL dump database to tar gz zipped file one-liner"

Drupal CSS Load Order

Posted by Lee Powers

When creating an HTML5 CSS site often I want to add in a CSS reset before any other Drupal CSS. BUT I'll also need to make sure my theme's CSS loads after every other stylesheet - this is the cascading in Cascading Style Sheets - if two stylesheets are loaded into a page and both define a style for the BODY tag, the last stylesheet loaded will have override the previous.

» Read more "Drupal CSS Load Order"

Drupal 7 create a page template for a custom node content type

Posted by Lee Powers

In D7 (Drupal 7) it's relatively straightforward to create a template for a custom node content type. For instance on this site I have a custom node type called "Project" which represents a project I've worked on and want to list in my freelance developer portfolio.

The Drupal 7 theme system is layered - meaning there's a default template file for rendering all nodes which can be overridden by a freelance developer to customize the rendering of all nodes or of a particular custom node type.

» Read more "Drupal 7 create a page template for a custom node content type"