Posts Tagged ‘php’

How to check to see if there are pages or posts before displaying in WordPress

When I’m programming a new theme in WordPress I’ll often want to check to see if there are going to be any results before I write content to the page, but often the process of calling the results will display it.

For example, if I want to list a series of pages inside a <ul> tag I first want to know if there is going to be a list of pages to write otherwise I will be writing an opening and closing <ul></ul> with nothing in the middle or worse, a title as well. To avoid this, here’s what I do:

[source lang="php"]<?

$list = wp_list_pages(‘echo=0′);

if ($list) {
echo "<h2>My pages</h2>";
echo "<ul>";
echo $list
echo "</ul>";
}

?>[/source]

The code example above simply uses the echo=0 option to preload the page list results into a variable called $list, next I simple check if $list has a value and if it does, I write the header and <ul> tags as well as the variable $list. If there are no pages, nothing is written.

 

I’ve build a similar function into three recent plugins, where you can preload the results into a variable using a show attribute by setting the value to false:

  1. $list = scheduledPosts(’show=false’);
  2. $list = randomPosts(’show=false’);
  3. $list = popularPosts(’show=false’);

Easy Popular Posts Plugin for WordPress

While I was working on my new theme for thisismyurl.com I came across the need to publish a series of popular posts in the side bar and so I put together a simple plugin for WordPress. The tool works like most WordPress theme calls and features:

  • Customizable number of links returned
  • Customizable before and after to ensure you can display the results
  • The ability to echo or return results
  • Let’s you control how popular a post should be

To use the plugin, install it to your WordPress website and edit your theme files by placing the following code:

General results
Without passing any parameters, the plugin will return ten results or fewer depending on how many posts you have.

[source lang="php"]&amp;lt;?php popularPosts();?&amp;gt;[/source]

Specific number of results
If you would like to return a specific number of results as your maximum:

[source lang="php"]&amp;lt;?php popularPosts(‘count=10′);?&amp;gt;[/source]

Altering the before and after values
By default the plugin wraps your code in list item (

  • ) tags but you can specify how to format the results using the following code:
    [source lang="php"]&amp;lt;?php popularPosts(‘before=&amp;lt;p&amp;gt;&amp;amp;amp;after=&amp;lt;/p&amp;gt;’);?&amp;gt;[/source]

    Echo vs. Return
    Finally, if you’d like to copy the results into a variable you can return the results as follows:

    [source lang="php"]&amp;lt;?php popularPosts(‘echo=false’);?&amp;gt; [/source]

    Minimum Comments
    To ensure you only return truly popular articles, you can limit the returned posts to posts with a minimum number of comments

    [source lang="php"]&amp;lt;?php popularPosts(‘comments=10′);?&amp;gt; [/source]

    Download the plugin

    Support forums are now online! If you have any questions, please visit http://forums.thisismyurl.com.

  • Easy Random Posts Plugin for WordPress

    While I was working on my new theme for thisismyurl.com I came across the need to publish a series of random posts in the side bar and so I put together a simple post randomizer for WordPress. The tool works like most WordPress theme calls and features:

    • Customizable number of links returned
    • Customizable before and after to ensure you can display the results
    • The ability to echo or return results

    To use the plugin, install it to your WordPress website and edit your theme files by placing the following code:

    General results
    Without passing any parameters, the plugin will return ten results or fewer depending on how many posts you have.

    [source lang="php"]&lt;?php randomPosts();?&gt;[/source]

    Specific number of results
    If you would like to return a specific number of results as your maximum:

    [source lang="php"]&lt;?php randomPosts(‘count=10′);?&gt;[/source]

    Altering the before and after values
    By default the plugin wraps your code in list item (<li>) tags but you can specify how to format the results using the following code:
    [source lang="php"]&lt;?php randomPosts(‘before=&lt;p&gt;&amp;after=&lt;/p&gt;’);?&gt;[/source]

    Echo vs. Return
    Finally, if you’d like to copy the results into a variable you can return the results as follows:

    [source lang="php"]&lt;?php randomPosts(‘echo=false’);?&gt; [/source]

    Download

    Download the plugin.

    Support forums are now online! If you have any questions, please visit http://forums.thisismyurl.com.

    21 Reasons why you don’t need Analytics and some other cool finds.

    I came across this great piece 21 Reasons Why You Do NOT Need Web Analytics at webanalyticsworld.net after reading Jordan’s You Don’t Need Web Analytics piece over at marketingpilgrim.com, I won’t bore you with the details here but both articles are worth a quick look and certainly true.

    Anna Linnea, who inspired my article 10 of the Sexiest Web Headers on the Planet went and changed her header but that’s OK because it’s still pretty cool and she wrote a very cool technical piece on WordPress comments and PHP that I think is well worth the read. Chris Bavota also has a new piece called A New Comment Editor.

    Blog Oh Blog has a new contest (WordPress Theme Design Contest – Win $300) and Dosh Dosh has a really cool piece on Twitter Marketing: Why You Don’t Need to Mass Follow Users, which goes back to one of my earlier problems with Twitter and why I don’t get Twitter.

    OK, I’m off to YouTube for the rest of the day but let me know if there are any really cool sites you think I should check out.

    How much does a new web site cost?

    Websites are one of the funniest things to quote, literally a website range from absolutely nothing (Build a Website) or just $100 (Can you put up a website for less than $100?) to thousands, tens of thousands or even millions or dollars to build so how do I effectively answer a question like How much does a new web site cost?

    Let’s look at a couple of different methods for estimating what you should spend on the web.

    Do it yourself.

    Technically, everything you need to build an effective website is already on your computer or can be downloaded from the Internet for free. As long as you have access to a few basic things, you’re set and the cost of building a website is nothing. Here’s what you’ll need:

    1. A text editor such as Notepad or Textedit
    2. An FTP client to connect to your hosting provider
    3. A hosting account on a web hosting provider
    4. A domain name
    5. Basic HTML skills and/or a copy of WordPress
    6. Knowledge of PHP or similar programming language

    Hiring a Professional

    If you don’t know how to do it yourself or prefer to hire a professional, the cost to build a website is pretty difficult to estimate because it involves two factors;

    1. How complicated is your website
    2. How expensive is your web professional

    When you’re estimating how much time your website will take, I think it’s important to get three quotes from three qualified web professionals. As tempting as it is to work with just one, when it comes to the future of your business it’s a great idea to get a few different opinions but as for the quote itself? Expect it to range dramatically.

    Sample Pricing

    While I can’t speak for other designers / developers I can tell you that I know many web professionals who price themselves in one of three price ranges:

    • Entry Level – $20 – $35 / hr
    • Mid Career – $40 – $60 / hr
    • Senior Level – $75 – $100 / hr
    • Webmasters – $150 (+) /hr

    One of the problems answering the question however is that the amount of time that it takes for somebody to do a job varies, even within the same career levels. For example, my time to SEO a website is fairly low because it’s what I specialize in but my great friend Chris Bavota does it just as fast even though he considers himself less experienced. On the other hand, my custom programming is faster in both prototyping and execution … his rich media on the other hand? Faster and cleaner than I could ever dream. This is why the same project, quoted from three designers / developers can be dramatically different.

    A basic website – If your looking for a small website, using WordPress as a content manager, minor customizations to a theme, advice to select some great plugins and installation on a new domain name you should expect to pay for anywhere from three to ten hours of time plus consulting of course.

    A large business website – Larger websites are significant investments for a company, while they’re equally difficult to judge one measure that I’ve found fairly accurate in the past is to look at the companies annual print advertising budget and assume the development of a website to compete will cost 75% of the existing budget for the first year and 50% for each additional year. 

    For example, if your yellow page ad budget is $150 per month ($1,800/yr), you should anticipate your website costing ~$1,350 once completed. This of course represents between 10 and 60 hours of time for a web professional, depending on their experience and level.

    A website just like X -  Just to put it out there (because I’m asked the about twice a month), building a website like another popular site is possible, so here are some quick estimates:

    • Facebook – 4,000 hours development & 300 hours per month marketing / maintenance
    • MySpace – ditto.
    • Elance – 2,500 hours development & 200 hours per month maintenance
    • eBay – 2,000 hours development & 200 hours per month maintenance
    • Plenty of Fish – 2,000 hours development & 200 hours per month maintenance

    What should you ask your web design firm?

    There are a couple of things that I would always recommend you ask your web design firm before getting started with them.

    • Talk to some previous clients to see how responsive and supportive the firm was
    • Ask a few previous clients what the cost / timeline overruns turned out to be
    • Did they find working with the team pleasant?

    Web designers are notoriously grumpy sometimes, so you should be able to forgive a little bit of that (it’s a stressful job, like working in a kitchen) but what matters (also like working in a kitchen) is how well the final piece turned out and if it got out on time.

    Placing Google Analytics Code in a Dreamweaver Template

    This is just a quick tip today, I got out of a training session and realized that a lot of people are still having a hard time understand Google Analytics so here are a few things for you to keep in mind.

    First, for Analytics to be effective you need to include the code on all your webpages (not just the homepage). To do this in Dreamweaver, follow these simple steps:

    1. copy the code from your Google Analytics home page
    2. open dreamweaver and edit your template file
    3. switch to Code View
    4. place the Analytics code at the bottom of the file, between the </body> and </html> tags

    Why between those two tags?

    The Google Analytics code works by calling a remote script from Googles servers. Somethings this takes a bit of time, while it’s loading your webpage might stutter so let’s load all the page and display it to users first.

    How to add Analytics to WordPress?

    If you’re running WordPress, you can follow the steps above pretty well except in your case you’ll want to edit the footer.php which is found in your wp-content/themes/[yourthemename]/ directory.

    Why are websites so hard to make?

    Wow, I’ll tell you honestly that one of the questions I tend to get asked a lot (and drives people to my website) is Why is a website so hard to make? Actually, that question (or a version of it) accounts for a few unique visits every day so to help answer the question, I’ve explain a few of the reasons that websites are so hard (or expensive) to build.

    First, the Web is inconsistent.

    This is possibly the worse news for people just starting out, but it’s the horrible and sad truth. Web sites are nothing more than code, it’s not terribly complicated once you understand the basics of it but it’s still just a bunch of gobbly gook until it’s read by something else … and there’s the problem. Each ’something else’ is different. Web code is read by popular web browsers such as Internet Explorer, Safari, Chrome and FireFox but that’s only the tip of the iceberg because Internet Explorer has several versions in common operation today (versions 5,6,7 and now 8) which all display the web dramatically differently. 

    Once you get past the basic issue of browsers, you need to think about operating systems. How many computer operating systems can you name? Obviously there’s Windows and Mac right? Great … except … you also have Windows Vista, Windows XP, Windows ME, Windows 2000, Windows NT, Windows 7 and Windows Lite to content with, Macintosh OS X Leopard and Macintosh OS X Pather. That’s got to be it right? Not so fast, what about Linux and Unix? There are hundreds of variations of computer based operating systems, each running one of a dozen web browsers for countless combinations but at least that’s all there is to worry about … except for handhelds (iPhones, BlackBerries, Windows Mobile Devices) and gaming consoles (Nintendo Wii, Microsoft XBox, XBox 360, Sony PSP, Sony Play Station 3) and TV based internet consoles … I hope that I’ve made my point, one of the reasons the Internet is complex to publish for is because there are too many “things” to publish for, instead we’re forced to practice failing gracefully.

    The Web lacks a standard language.

    Problem number two for somebody just starting out in the great big world of the web is that there is no standard programming language for the Internet. At it’s core, the World Wide Web is programmed in a language called HTML right? Everybody knows this, except it’s wrong.

    The web is published in a language called xHTML which is based on HTML, but some people in the community didn’t agree with xHTML so they created other strains of HTML. As a result, we have HTML 1.x, HTML 2.x, HTML 3.x, HTML 4.x, DHTML, xHTML, xHTML 1.1 and xHTML 1.1 SE. Soon we’ll also have xHTML 2.0 as well as xHTML 5.0 … don’t ask.

    Now, as we discussed above, there are at least a few dozen major operating systems and each of those has at least a handful of web browsers, plus a ton of mobile devices all designed to interpret some or more of the languages that the web is built on but it’s important to note that not all web browsers agreed on which standards are acceptable or for that matter which codes, structure, text or tags from any standard would be accepted. As a result, a web page developed to be viewed in Microsoft Internet Explorer 5 may (or may not) be visible in other web browsers including other versions of IE.

    Scripting on the Web

    Now, once you get past the basic problem of coding for some browsers while ignoring others and you pick one of the standards to adhere to, you’ve got to take the time to start writing more than simple content and for that you need what’s called a scripting language of which … there are many.

    Most scripting languages such as PHP, Python, ASP, ASP.net etc. execute on the web server (where the website is hosted) but some such as JavaScript execute on the web browser after being downloaded (not to be confused with Java which is not a scripting language but a programming language and completely different). These scripts are what power everything from a simple email form to complex social media giants such as FaceBook.

    After you’ve picked the scripting language you wish to use and ensured that it’s compatible with your hosting account (where you store your website for others to access it) you’re all set and ready to start building your first website.

    How to handle it all

    I’m lucky, I’ve been building websites since 1996 which means that in my very (very) long career I’ve seen countless technologies come, go and die. So my advice to people getting started in the industry is a lot like Benjamin’s in Animal Farm, Web Masters much like Donkeys know that times change but stay the same, simply pick your standards and be the best developer in that selected field. You will be mocked, scorned, insulted and ignored by others in the industry for your choices but in just a few years … everything you know will be outdated and you’ll have to relearn new tools anyways so don’t worry so much.

    “Only old Benjamin professed to remember every detail of his long life and to know that things never had been, nor ever could be much better or much worse – hunger, hardship and disappointment being, so he said, the unalterable law of life.”

    - George Orwell, Animal Farm,

    Web Jobs and What People Really Do

    These days I spend a lot of time looking at job postings around the Internet, it’s a tough place to be especially since most recruiters have no idea what web people do and those who are aware of the industry are often completely unaware of the ridiculous nature of their requests. The other day I saw a posting on Monster for:

    a Senior Web Developer with 6+ years Adobe Flex experience and a working knowledge of Word, office printers and networks.

    First … Flex was only invented in 2004. Second, it’s a specialty … Flex experts are like dessert chefs, asking them to be good at washing dishes in addition to making authentic French meringues will not get you qualified candidates, it will get you dish washers. Here’s a quick look at what I believe are accurate descriptions of jobs in my industry:

    Web Designers

    A web designer is a pixel pusher, they use Adobe Photoshop or similar tools to create Graphical User Interfaces to be converted to Hypertext Markup Language. Ideal web designers sway to one of two sub specialties, they are either functionally capable Usability Specialists or entry level Web Developers in addition to being a designer. Web Designers are artists, akin to Graphic Designers and photographers and rarely have a university degree, though most go to college.

    Multimedia Specialists

    There are sadly, dozens of areas of Specialists in the Web field from those who specialize in Flash or Flex to QuickTime, Shockwave, 3D artists and those who work in the video or audio production fields. Often these Specialists will have backgrounds in design as well as their media specialization. Few in the industry have degrees, and only a handful have college diplomas since the work is profitable from an early age.

    Web Developers

    A web developer programs websites using the Hypertext Markup Language to convert a designer’s artwork into a language compatible with web browser technology. They are also capable of programming the interactivity of a website using PHP or ASP based languages, JavaScript or other languages. Web Developers are coders, similar in nature to C++ or Java computer programmers. 

    Usability Specialists

    The web is a marketing platform, the job of a Usability Specialist is to ensure the average user can successfully navigate a website and achieve the business objective, regardless of what the object may be. Often the Usability Specialist is also the Project Manager and has an obsessive nature geared towards Quality Control and meeting objectives.

     

    Web Publishers

     

    A Web Publisher is a data entry person, they’re job is to convert information from print or electronic form into web based content following strict document structure guidelines. After the designer and developer have put together the skeleton of a website, the Web Publisher works with Copyrighters and the Marketing team to ensure all content is placed in the right places before launching a website.

    SEO Specialists

    Unique to the Web, an SEO Specialist is an Organic Marketing professional who’s sole purpose is to increase the traffic rate of a web property through non paid advertising means. Often the SEO Specialist will also manage online advertising programs, purchasing and real world marketing but his/her real goal is to broaden the success of a website without paid placement.  

    Web Managers

    The Web Manager is the business brains of a website. They’re job is to manage timelines, budgets, analyze Analytics and convert web traffic to measurable business. In many smaller organizations they’re also Web Generalists capable of lending a hand in all other areas of the puzzle, those who have mastered multiple ares of expertise are often called Web Masters. This is a tough job, it involves managing the egos of artists and the surly nature of programmers while meeting tough deadlines.

    Network Administrators

    I like to call NA’s the Backend Boys but for some reason they don’t like that title. A Network Administrator is a specialist which every Web person needs, they don’t get a lot of glory and they’re often (rightfully so) the first to get blamed with things go wrong but a Network Administrator’s job is to run the hardware (physical computers) the Web teams software (the website) operates on. They spend long hours ensuring email, servers, data streams and corporate software work.

    Director of Technology

    These days, our companies have become technology saturated. The role of a Director of Technology is to understand the business objectives of the organization and utilize cost savings methodologies to deliver the best computer solutions possible. Simply put, they’re job is to always do more with less while ensuring the best people are capable of delivering timely solutions and the rest of the organization sees technology as a friendly resource, not an aggravation.

    Chief Technology Officer

    The CTO title always interests me, there’re rarely a Vice President of Technology in an organization so I’m not sure if the title is a silent salute to Star Trek. The job of the CTO is two fold, first they have to keep the technology of a whole organization flowing smoothly and they also have to plan for future technologies by knowing where the company needs to be down the road. Their job in short is to lead the whole technology team for the management team and to solve the problems of the business through new, innovated methods.

    How to Secure Your WordPress Website

    Running a WordPress website is one of the easiest ways to run a high quality, free web site content management engine but since there are millions of other websites running the same software, there are lots of bad guys out there who would like nothing more than to break into your website. So how do you stop them? In this article I’ll examine some processes your blog should implement to ensure it’s more secure than the ‘out of the box’ version of WordPress.

    Basic Security

    Plugin Directory

    Step One of any WordPress security installation is to hide the contents of the plugin directory. By default, WordPress ships with the directory exposed (it can be found by typing http://[yourwebsite]/wp-content/plugins/) but this allows the bad guys to see what plugins you’re running and possibly take advantage of them. To solve this, simply upload an empty file named index.html or index.php into the base plugin directory.  Another very easy way to do this for your entire WordPress site is to simply add Options -indexes to your .htaccess file. This tells your web server to never list directory contents.

    Quick Note: .htaccess files are funny things, they don’t have a filename in the traditional sense so when you download them, all you download is the extension (filename.extension). This can make working with them tough. What I like to do is rename the file -.htaccess or something similar before downloading it, which allows Windows computers to properly interact with the file.

    Limit Access to the Admin

    Step Two of the basic plan of attack is to limit access to your administration tool. An .htaccess file is a server level control file, meaning that it interacts with the web server before it interacts with a web browser, what we want to do is limit the IP addresses of computers to your wp-admin directory. Need a more basic explanation? Each computer on the internet has a unique Internet Protocol (IP) address made up of four numbers ranging from 0 to 256 for example, 123.456.123.456 this number reflects your unique signature on the Internet. What we want to do is control which computers can access your account.

    To do this, first we need to know what your IP address is. Luckily there’s a website for that at http://whatismyipaddress.com/ which will tell you what your current IP address is. After you have that, create a new file called .htaccess on your desktop and add the following code to it:

    AuthUserFile /dev/null
    AuthGroupFile /dev/null
    AuthName “Access Control”
    AuthType Basic
    order deny,allow
    deny from all
    allow from [paste your IP address here]

    Once you upload that code to your wp-admin directory only computers from the IP address you specified will be able to access your WordPress admin directory. You can add multiple allow from lines to ensure you can access your site from work or home. If you ever need to access your admin panel from outside the IP range, simply comment (place a # symbol) before the deny from all line and you’ll be able to access it normally.

    One final note here, since many people have dynamic IP addresses (they change whenever you reboot your internet connection) you might want to check with your Internet Service Provider to determine their IP range. For example, once you know that your IP address is always 142.167.66.[0- 255] you can use the allow from address of 142.167.66.* so anybody in your local subnet group (the last octal) can access your admin directory. A little less secure but still better than allowing the whole world to access it.

    An Extra Level of Password Control

    password protect directory 300x199 How to Secure Your WordPress Website imageJust like the .htaccess file can be used to limit access from specific IP addresses it can also be used to force a server level username and password check before prompting you to input your WordPress username and password. You can do this fairly easily if you’re hosting with BlueHost or if you’re using another hosting company you can create a secure login using an .htaccess file and .htpasswd files or the AskApache Password Protect plugin. This process is a little more complex but a great extra layer of security.

    Change Your Admin Account

    By default the most powerful account on your WordPress website is called admin, since everybody in the world knows this they only need to guess your password but if you change the admin account name, you make guessing both your username and password infinitely harder. One other point here, since your password is case sensitive (A and a are different letters) you should always use long, complex passwords that mix uppercase and lowercase letters, at least one number and if possible a symbol such as an ampersand (&) or dollar sign. The more complex you make your password, the less chance somebody will guess it.

    WordPress Version

    Some WordPress themes include a line such as <meta name=”generator” content=”WordPress <?php bloginfo(’version’); ?>” />  in the header.php file. While this is great for WordPress it’s a security blunder since you’re announcing to the world which version of WordPress your using and if it’s not the most recent … which security holes your website is vulnerable to. Simply remove this line from your header and you’ll be more secure.

     

    WordPress displaying security issues

    WordPress displaying security issues

    The next step when it comes to security with regards to versions is to always upgrade to the most recent version promptly. I recommend upgrading your website (and your plugins) as quickly as possible after a new release has been updated.  You’ll see from the graphic to the right that my hotel web design company Getaway Graphics hasn’t had some of it’s plugins or base code upgraded in weeks, this is a major security flaw which could lead to hackers gaining access to my files. Luckily, I did this to demonstrate the potential flaws and the site is actually perfectly safe.

    Always upgrade your website and your plugins to the most recent version after you have done a backup of your site files and data. As a bit of shameless self promotion, let me pipe in here that for a fairly reasonable fee, I can do this for you on a monthly schedule or train you how to maintain and monitor your website.

    Secure Your .htaccess file

    I think we’re now all aware how powerful the .htaccess file is correct? Great, so let’s secure it simply by adding the following code to the very bottom of the file:

    <Files wp-config.php>
    Order Deny,Allow
    Deny from All
    </Files>

    This simple piece of code makes it impossible for people to see all the security customizations you’ve done to your blog.

    Report Issues

    WordPress is, at it’s heart a community project. If there’s something wrong and you discover it, send a bug report immediately so the team can fix security holes. This will make the software more secure both for you and the rest of the WordPress users.

    Security Plugins for WordPress

    Beyond the common sense security steps outlined above, there are several plugins related to security which every WordPress website should be running:

     

    • Login Lockdown – records failed attempts to access your WordPress admin panel. Frankly, if you don’t know people are knocking on your door … how do you know to protect it?
    • WP Security Scan – tests your website for common security holes.
    • WP Database Backup – backs up the content of your database regularly. Not really a security tool but it will allow you to restore to a previous version if you ever need to.
    • AskApache Password Protect – add a password to your wp-admin directory.

     

    Other Great Sources

    While I was putting together this article, I had help from some other sources on the net including:

    One Final Note …

    wordpress How to Secure Your WordPress Website imageThe steps I’ve outlined in the above article are all fairly straight forward and necessary to ensure a strong, safe WordPress blog but I appreciate some people simply lack the technical confidence to perform the steps effectively. I’m available as a WordPress consultant and can generally perform all the necessary upgrades to your WordPress website quickly, effectively and easily so why not give me a call?

    Automatically Title Casing Titles in WordPress

    If you’re anything like me, you’re a little lazy when it comes to title casing text in WordPress but as we all know, it’s really important to be consistent across your web pages, so what’s the answer? As I often comment … it’s time for technology to come to the rescue.

    Using a simple code snippet I came across on Camen Design, you can easily add a small function to your website, which in turn will automatically convert all your headers to a consistent format.

    Start by inserting the following code in your header.php file:

    function titleCase ($s_title) {
    	//remove HTML, storing it for later
    	//         html elements to ignore  | tags  | entities
    	$regex = '/<(code|var)[^>]*>.*?<\/\1>|<[^>]+>|&[^\w]+;/';
    	preg_match_all ($regex, $s_title, $html, PREG_OFFSET_CAPTURE);
    	$result = preg_replace ($regex, '', $s_title);
    
    	//break by punctuation, find the start of words
    	preg_match_all ('/[\w&`\'‘’"“\.@:\/\{\(\[<>_]+-? */', $result, $matches, PREG_OFFSET_CAPTURE);
    	foreach ($matches[0] as &$m) {
    		//find words that should be lowercase
    		if ($m[1]>0 && mb_substr ($result, $m[1]-2, 1) !== ':' && preg_match (
    			'/^(a(nd?|s|t)?|b(ut|y)|en|for|i[fn]|o[fnr]|t(he|o)|vs?\.?|via)[ \-]/i', $m[0]
    		)) {
    			$m[0] = mb_strtolower ($m[0]);
    
    		//brackets and other wrappers
    		} elseif (preg_match ('/[\'"_{(\[]/', mb_substr ($result, $m[1], 3))) {
    			$m[0] = mb_substr ($m[0], 0, 1).mb_strtoupper (mb_substr ($m[0], 1, 1)).
    				mb_substr ($m[0], 2)
    			;
    
    		//both of these cases are no change, thus if not matched fall back to capitalisation
    		} elseif (!(
    			preg_match ('/[A-Z]+|&|[\w]+[._][\w]+/', mb_substr ($m[0], 1)) ||
    			preg_match ('/[\])}]/', mb_substr ($result, $m[1]-1, 3))
    		)) {
    			$m[0] = mb_strtoupper (mb_substr ($m[0], 0, 1)).mb_substr ($m[0], 1);
    		}
    		//substitute the change into the title
    		$result = substr_replace ($result, $m[0], $m[1], strlen ($m[0]));
    	}
    	//restore the HTML
    	foreach ($html[0] as $tag) $result = substr_replace ($result, $tag[0], $tag[1], 0);
    	return $result;
    }
    

    Next, you’ll need to do a search and replace your entire WordPress theme directory for the current title tag (<?php the_title(); ?>) and replace it with the new tag (<?php echo titleCase(the_title(”,”,FALSE)); ?>). As always, be sure to backup your code before doing this. What the new code has done is told WordPress to insert the title as variable instead of displaying it. Once stored in memory, the titleCase function is called and does it’s job of standardizing the text.

    I found a few other really good resources for title casing in PHP in SitePoint and WeberDev but the PHP resource for UC words was one of the best, albeit a little technical, with a little bit of PHP knowledge you should be able to modify the code to work with most CMS applications. Make sure to read about speeding up WordPress however, as this function will certainly add to the server load of a popular website.

    Fundraising Thermometer Plugin for Wordpress

    The plugin interface, for WordPress

    Features

    Example of a fund raising image from the new plugin

    The fund raising tool is a true WordPress plug-in, testing with WordPress 2.7 and fully functional. It features:

    • W3C compliant Cascading Style Sheets (CSS)
    • Dynamically updated text including target and current fund status
    • Money formating options for use internationally
    • Theme options, allowing designers to customize the look of the thermometer
    • Call either the graphic or a formated number to display in text.

    Admin Features

    The new interface allows uses to set both the current amount (what has been raised) as well as the target amount (what you want to raise). The script automatically generates the ten steps in between and displays them for the user.


    The plugin auto detects if the money_format() function is present and will use it automatically if found, otherwise it will display the currency using the number format function automatically.

    How It Works

    To display the current amount of money raised (in currently format) place the following code in your theme:

    <?php echo show_ourprogress();?>

    For a graphical version (by default the thermometer), include the following code:

    <?php show_ourprogress_graphic();?>

    Where to Get It

    The plugin can be downloaded from the official WordPress repository: 

    download file Fundraising Thermometer Plugin for Wordpress image

    How You Can Help

    I love developing plugins for WordPress and do my best to always keep them free but of course it take a lot of time and effort to build these plugins so if you’d like to say thanks, the best way is to take a few moments and write about the plugin on your own website, include a link to my website from your posts or download and rate the plugin on the official plugin directory. 

    Support forums are now online! If you have any questions, please visit http://forums.thisismyurl.com.

    Show both links and pictures in WordPress wp_list_bookmarks()

    showingbothlinksandpics 153x300 Show both links and pictures in WordPress wp list bookmarks() imageAs some of you may have noticed, I updated the design for my site this week. It was a pretty major overhaul of the basic code, although it is still 100% WordPress. The upgrade that I’ve had the most messages about is my links list at the bottom of the page. It uses the standard WordPress Links list with a few minor scripting changes.

    By default, WordPress wp_list_bookmarks() will display either the graphic or the title of your link but not both. If there is a graphic image set, it will simply ignore the title and output only the graphic. If no graphic is present, it will only output the text. Not exactly what I wanted.

    What I wanted was what Jeremy had. So I set about trying to find the code to do this in WordPress only to find out that it simply didn’t exist. What I did find was a lot of people grumbling about it, so  I fixed the problem using WordPress’s built in get_bookmarks() function.

    Here’s what I did:

    <strong>What I’m Reading</strong>
    <ul><?php 

    $linklist = get_bookmarks(‘category=70′); 
    foreach ($linklist as $site) { 
    echo “<li>”;
    if (strlen($site->link_image)>2) {
    echo “<span class=’linkimage’>”;

    echo “<a href=’”.$site->link_url.”‘ title=’”.$site->link_description.”‘ rel=’me’><img src=’”.$site->link_image.”‘ alt=’”.$site->link_name.”‘/></a>”;
    echo “</span>”;

    } else {
    echo “<span class=’linkimage’></span>”;
    }

    echo “<span class=’linkname’>”;
    echo “<a href=’”.$site->link_url.”‘ title=’”.$site->link_name.”‘ rel=’me’>”.$site->link_name.”</a>”;
    echo “</span>”;
    echo “</li>\n\r”;
    }
    ?></ul>

    For those of you who know PHP what I did was pretty simple but for the rest of you, here’s the basic breakdown:

    $linklist = get_bookmarks(‘category=70′); 

    Get the values of category #70 (I only wanted those links) and load them into a variable.

    foreach ($linklist as $site) { … }

    Loop through the variable.

    if (strlen($site->link_image)>2) { … }  else { … }

    If the link_image value (that’s where the image is stored) has a value of more than two characters, do this. Otherwise, do something else. For the record, sometimes the value returned a false positive when testing for isset() so I choose to do a strlen() instead.

    echo “<span class=’linkimage’>”;
    echo “<a href=’”.$site->link_url.”‘ title=’”.

    $site->link_description.”‘ rel=’me’><img src=’”.$site->link_image.”‘ alt=’”.$site->link_name.”‘/></a>”;
    echo “</span>”;

    The code above displays a <span> tag. I repeat the process if there’s no image found using an empty <span> tag to keep the text alignment appropriate.

    echo “<span class=’linkname’>”;
    echo “<a href=’”.$site->link_url.”‘ title=’”.$site->link_name.”‘ rel=’me’>”.$site->link_name.”</a>”;
    echo “</span>”;
    echo “</li>\n\r”;

    Finally, I display another <span> called linkname which stored the text based hyperlink to the site. 

    That’s all she (actually he) wrote … do you have any suggestions how to improve this code? Let me know and I’ll owe you a pint. Also, if you use this code please post a link to your website below so that I can see it in action. Thanks.

    Federal Government of Canada

    Over the past few years, I’ve had the pleasure of working with several government departments to provide web development and programming services. Below are a few samples of key projects.

    nrcan sbml 150x150 Federal Government of Canada imageWritten in PHP, the SBML web interface allows employees of Natural Resources Canada (NRCAN) to search a FileMaker Pro based database using an XML based data conversion method. The tool is housed as part of the national internet and allows the staff to find research papers from across the country.

    nrcan knowledgeassetinventory 150x150 Federal Government of Canada imageAnother PHP powered web search tool written for Natural Resources Canada (NRCAN), the tool allows staff throughout the country to search for knowledge assets, photos, illustrations and technical documents. The web tool uses PHP to connect to a FileMaker Pro database server through an XML interface. As with all government projects, this one uses strict xHTML and CSS to ensure compatibility.
    nrcan briefingnotes 150x150 Federal Government of Canada imageDeveloped for the Minister of Natural Resources, the Briefing Notes database was created to allow easy access and search tools for sensitive materials throughout the organization. Each document was automatically indexed and uploaded to a FileMaker Pro database which in turn linked to web based search tool. Included in the tool was document versioning control to track multiple versions of the same document and commenting, so additional feedback could be provided.
    agriculture pool 150x150 Federal Government of Canada imageThe POOL database was created for the Central Experimental Farm of Agriculture and AgriFood Canada to provide genetic oat data for scientists throughout Canada. Using PHP with a MySQL database, the oat data provided scientists with the ability to link related research and increase the speed materials became available to other research scientists.