Using both Pages and Categories for WordPress’ Page Menu

A lot of Wordpress themes made use of the handy WordPress page_menu() function that generates the main page horizontal page navigation bar at the top of the website. However, there is one annoying little restriction this handy functionality comes packaged with, namely:

How do I use both pages and categories for the main navigation page menu bar at the same time?

Frustrating, really it is.

However, after digging around a little I have come up with a little hack that solves this dilemma for us, though be warned, you purists out there are not going to like it – after all, it does involve editing a core WordPress file – meaning in essence that should you upgrade your WordPress installation you’ll most likely have to add in this hack all over again.

But hell, if you don’t mind that then read on a little – after all, as you can see above on my blog’s menu, it seems to be working damn well thank you very much! :)

So here goes. First, locate the post-template.php file that will be sitting directly in your /wp-includes folder. Open that file and browse to line 836, where you should come across a line that reads:

$menu .= str_replace( array( "\r", "\n", "\t" ), '', wp_list_pages($list_args) );

What this line is doing is basically building up the return menu string by calling the built in wp_list_pages WordPress function. So our trick is going to be to extend that returned menu string by adding on our category listing to the end of it in the correct format that it expects.

And these are the lines you need to add directly after the line above:

$list_args['include'] = '17,77,39,21,80,46,27,4' //where these are valid catergory IDs;
$menu .= str_replace( array( "\r", "\n", "\t" ), '', wp_list_categories($list_args) );

As you can see, all we are doing is making use of WordPress’ wp_list_categories call which we’ve extended by asking to include some specific categories only. (Of course, we could skip this step by leaving out the first of our added lines, or perhaps change it to exclude certain categories by changing the call to ‘exclude’).

In any event, saving the changes to our file and uploading it back to the server, you should now find that on reloading your website that all of a sudden you have both pages and categories listed side by side in the main navigation menu.

Nice! :)

Posted in Technology & Code, Tutorials | Tagged , , , , , | Leave a comment

Ubuntu: Installing a Software Application from a Terminal

Installing a new software package via a command line terminal in Ubuntu Karmic Koala (and basically all the other versions preceding it) is deceptively easy thanks to the powerful apt-get command that is used as the interface into Ubuntu’s Advanced Packaging Tool (APT). It can be used to install new software applications, upgrade existing software packages, update the current package list index and even go as far as upgrading the entire Ubuntu system.

The usage of apt-get to install a software package (like the network scanner nmap for example) is as simple as entering:

sudo apt-get install nmap

Similarly, to remove a package you simply change the above command to:

sudo apt-get remove nmap

Note that you can specify multiple packages to be installed or removed, separated by spaces. So for example sudo apt-get nmap gedit would install nmap and gedit respectively. Apt-get is also quite useful for updating the package index, in other words the database that holds all the available packages from the repositories defined in the /etc/apt/sources.list information file. The command to do this is:

sudo apt-get update

Lastly, apt-get is even powerful enough to update your Ubuntu installation itself. First run an update against your package index (as above) and then type:

sudo apt-get upgrade

As for log files of apt-get activity, see /var/log/dpkg.log. For more help on the command, a simple apt-get help will suffice.

There. Now you know! :)

(And for an easter egg while you’re at it, you may as well enter apt-get moo. If you get an answer, well then at least you know that you have Super Cow Powers!)

Related Link: https://help.ubuntu.com/8.04/serverguide/C/apt-get.html

Posted in Tutorials | Tagged , , , , , , , | Leave a comment

Avoid HTML Special Characters in Your Querystring

I must admit, I was totally left scratching my head a couple of days ago while presenting a survey capturing site I had just finished whipping up, when all of a sudden the site stopped redirecting properly when tested in Internet Explorer (IE) using compatibility mode. Completely flummoxed as to why something that worked perfect fine in some browsers simply didn’t work in others, I stopped to have a quick peek at what might be causing the problem and when I saw what it was, I couldn’t help but break out into laughter.

In order to redirect my script after successfully pushing data into the database, I was using Javascript to change the window’s location to a URL I was specifically building up with some required GET variables attached. However, my ordering of variables in the querystring couldn’t have been more unfortunate had it tried – you see, I was using a variable entitled reg and attaching it to the URL as &reg.

Now those of you with sharp eyes and a little bit of HTML knowledge will immediately slap your heads and go “duh” out loud, because yes, I had managed to accidentally declare a reserved HTML special character, namely ® which is of course translated to the registered trademark symbol. So my querystring was still working but with one less required GET variable as it was being lost in the redirect thanks to the older browser translating it into the actual symbol – hence causing that extreme sense of head-scratching puzzlement I had experienced earlier!

So be a pal and check your variable order in your querystrings carefully. You never know what you might inadvertently creating! :)

Posted in Technology & Code | Tagged , , , , , | Leave a comment

AutoComplete Country Selection using jQuery

Marc-Antoine Ross has knocked together a great little jQuery plugin, or extension if you will, which gives you a nice autocomplete country selector textbox (with little flags).

So in order for someone to provide you with their nationality, all they now need to do is start typing in a little form textbox provided and after two letters or so, they can simply select from the available drop down list the country which they wish to list.

The extension uses Jorn Zaefferer’s Autocomplete jQuery plugin, FamFamFam’s flag icon set and Aral Balkan’s ISO country data source in case you were wondering.

Related Link: http://www.devtaxi.com/tools/accountry/

Posted in Software & Websites, Technology & Code | Tagged , , , , , , , | Leave a comment

Photoshop: Text Tool Keyboard Shortcuts

In order to speed up your work using Photoshop’s powerful but sometimes quite frustrating text tool, here are a couple of handy keyboard shortcuts you might like to remember:

  • Commit text changes by pressing CTRL+Enter. (Pressing Enter on its own will just start a new line obviously!)
  • With all text selected, you can hide the selection colour with CTRL+H to see an accurate preview. Useful when working with colour in particular!
  • CTRL+Shift+Left or Right arrow keys selects the whole next or previous word.
  • CTRL+Shift+< or > decreases or increases the font-size by 2 points.
  • CTRL+Shift+ALT+< or > decreases or increases the font-size by 10 points.
  • CTRL+ALT+Left or Right arrow keys increase or decrease letter kerning by 100.
  • ALT+Left or Right arrow keys increase or decrease letter kerning by 20.
  • CTRL+ALT+Up or Down arrow keys move the text baseline up or down by 10.
  • ALT+Up or Down arrow keys move the text baseline up or down by 2.
  • CTRL+Shift+L, R or C aligns the paragraph of text left, right or center.

Finally, and although not a keyboard shortcut, double clicking on the T icon in the layers panel will actually select all text in that layer.

Useful.

Posted in Software & Websites, Tutorials | Tagged , , , , , , | 1 Comment

Send Highlighted Text and Link via Email Fast!

Arthur Sabintsev (aka LazyRussion) brings to us the brilliant little Firefox add-on named Email This! which basically allows you to right-click on any selected text on any webpage your are currently browsing and then send the highlight text, title plus link to an email recipient using GMail, Google Apps GMail, Yahoo or even standalone mail clients like Outlook Express or Thunderbird.

The amount of times I want to send an email to myself containing the exact data I just mentioned above for later reference is a lot, so this little add-on is certainly proving to be one hell of an effort saver! :)

To use, simply install as normal and once installed, set the necessary mailer preferences by clicking on the Options button under the Email This! entry on the add-ons page. Once set up, Email This! now becomes usable via either a toolbar entry or a right-click context menu option.

All that, all that is left is now to browse to a page, highlight a passage of text and click send! Brilliant I tell you! :)

Add to Firefox: https://addons.mozilla.org/en-US/firefox/addon/3102

Related Link: http://lazyrussian.com/my-projects/email-this-firefox-extension/

Posted in Software & Websites | Tagged , , , , , , , , , | Leave a comment

Force Your Script to Run Longer than Maximum Execution Time

I have to process some large CSV files that generate a lot of SQL statements that need to be executed. Naturally, trying to parse any of the files almost always results in my script spitting back that horrible maximum execution time exceeded error message, even though I’ve adjusted the maximum execution time setting in the php.ini file to as large as I dare go.

So how does one go about forcing a script to stay alive infinitely until it eventually finishes its job?

(Note: You really don’t want to apply what follows to an infinite loop snippet of code!)

Well, PHP does hand us the nifty set_time_limit() function that basically restarts PHP’s built in timeout counter, setting it to zero and then changing the new timeout value to the number of seconds specified in the function call. So for example, if the timeout default is 30 seconds and you call set_time_limit(20) 25 seconds into script execution, the script will now be able to run 45 seconds before timing out.

Now calling the function with a seconds parameter of zero is said to remove the time limit altogether, though in practice you may find that this doesn’t always work exactly how it should.

If for example your long-running script is based on a long loop operation, the easiest way to ensure your script doesn’t time out is to call the set_time_limit function with a specified timeout duration of say 20 seconds for each and every loop iteration.

This will in essence keep resetting the timeout counter and extending the maximum execution time, thus resulting in a script that has a potential to run just about forever! :)

[Unless of course you are running your script under II7 on a Windows Server 2008 machine where you'll have to adjust some additional Windows Environment parameters! Something to note though is that this function won't work if you are running PHP in SAFE mode. Unfortunately there doesn't seem to be a workaround for this instance! :( ]

Related Link: http://php.net/manual/en/function.set-time-limit.php

Posted in Technology & Code, Tutorials | Tagged , , , , | 1 Comment
 
Afrigator   Sorted bru, tagged by Amatomu.com