Gordonmac Dot Com

Mostly a web development blog

Posts Tagged ‘PHP’

WordPress_blue_logo.svg

WordPress – Custom taxonomy navigation menus

Posted: June 22nd, 2012 | Tags: | Posted in: Tutorials, Wordpress

The product of today’s messing around with WordPress custom taxonomies in a bid to finish a client website – I needed to  generate a navigation based on categories stored in a custom taxonomy. Here’s the gist of it: function displayTaxonomyNav($taxonomy, $baseURL) { $output = NULL; $rangeNames = get_terms($taxonomy, ‘orderby=id&hide_empty=0’); foreach($rangeNames …
Read more…

PHP_Logo

Validating e-mail addresses in PHP

Posted: November 17th, 2011 | Tags: | Posted in: PHP, Tutorials

This is easily the best function I’ve used for validating e-mail addresses in my PHP scripts and applications. function is_valid_email($email) { $qtext = ‘[^\x0d\x22\x5c\x80-\xff]’; $dtext = ‘[^\x0d\x5b-\x5d\x80-\xff]’; $atom = ‘[^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+’; $quoted_pair = ‘\x5c[\x00-\x7f]’; $domain_literal = “\x5b($dtext|$quoted_pair)*\x5d”; $quoted_string = “\x22($qtext|$quoted_pair)*\x22”; $domain_ref = $atom; $sub_domain = “($domain_ref|$domain_literal)”; $word = “($atom|$quoted_string)”; …
Read more…

WordPress_blue_logo.svg

Displaying recent posts in the WordPress sidebar

Posted: November 14th, 2011 | Tags: | Posted in: PHP, Tutorials, Wordpress

To add recent posts navigation to your WordPress blog, simple add the following code to sidebar.php. <h2>Recent Posts</h2> <nav id=”navigation-recent”> <ul> <?php $recent_posts = wp_get_recent_posts(5); foreach( $recent_posts as $recent ){ $date = date(“M d, Y”,strtotime($recent[“post_date”])); echo ‘<li><a href=”‘ . get_permalink($recent[“ID”]) . ‘” title=”Look ‘.$recent[“post_title”].'” >’ . $recent[“post_title”].'</a> ‘.$date.'</li>’; …
Read more…