Skip to content

Adding custom field data into WordPress menus

One of the problems almost everyone has with developing CMS driven websites is generating navigation menus; particularly pretty or heavily customised menus that can be easily updated by the end user.

WordPress (like Drupal) has a really excellent menu builder tool that you can use to easily create hierachical menus that you assign to “slots” in your theme. But what happens if you need to modify the standard html output of the menu? For example to pull in some information about the menu item’s target, such as custom field data about the Page or Post. You make a custom Walker…

Subclass Walker_Nav_Menu, include it in your theme’s functions.php file, and duplicate the start_el() method. If you look at the properties of the $item Object passed into the method, you’ll find that $item->object_id is particularly useful, as it refers to the WordPress Post/Page/CPT that this menu item is linked to. Now you’re in business and can just query for any post_meta information you want to inject into the menu html.

In the example below I added the css-id custom field data from the “target” to the list item’s id property. This means I can more reliably add bespoke background images and css styles to my uber-cool menus without having to worry about people deleting the initial menu entry I created. Which is nice for me, great for my customers, and even better for their customers…


function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 )
 {

//snip

$id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args );

//Add any custom ID added to the object...
 $css_id = ( get_post_meta($item->object_id, 'css-id', true) ) ? get_post_meta($item->object_id, 'css-id', true) : null;
 $id = ( $css_id ) ? $id . " " . $css_id : $id ;

$id = $id ? ' id="' . esc_attr( $id ) . '"' : '';
//snip
}

Need a freelance web developer near Bath to turn your web designs into reality? We build websites for small businesses, design agencies and freelance designers, quickly, efficiently and cost-effectively. Don’t hesitate to give us a bell on 01380 830224. We’re sure we can help!

Posted in Wordpress | Comments Off on Adding custom field data into WordPress menus

New MacBooks featuring USB3 – where now for Thunderbolt?

As widely anticipated, Apple have released updated MacBooks and MacBook Pros. Price points have generally stayed the same as before, but we’ve got some nice speed bumps and new features. Foremost among these is the introduction of USB3…

Where now for Thunderbolt?

It’s nearly 18 months since Apple first introduced Thunderbolt to the great unwashed, with the promise of unheard of data transfer rates and simplified cable managemen. I was one of those who upgraded to a Thunderbolt MacBook Pro and was positively salivating at the prospect of ultra fast backups, Thunderbolt Target Disk Mode and a slew of Thunderbolt adapters to work with E-SATA, USB3 and other devices. And what have we got? Precisely sod all in the consumer space (if you ignore a few hugely overpriced external Thunderbolt drives and lots of “vapourware”).

USB3 might not be technically as clever as Thunderbolt, but there are already cheap and widely available devices – you can get a 500GB external backup drive for around the same cost as a Thunderbolt cable! – which I think pretty much consigns Thunderbolt to the dustbin of “useful but too pricey technologies.” Sure it’ll find a niche in high-end video, but that niche will keep prices beyond the reach of mere mortals.

Which MacBook should I buy?

To be perfectly honest, I don’t think the landscape has changed that much. I still think the 13″ MacBook Pro is the sweet spot. The MacBook Air is very light, very thin, and very sexy. But if you want something light and thin, get an iPad for half the cost. The extra 1.5lbs the MacBook  Pro weighs gives you get a more robust, faster and more expandable laptop.

The MacBook Pro with Retina Display leaves me something in a quandary. My instinctively reaction is “that must look awesome” followed shortly by “will my Apps look rubbish until I upgrade to Retina ready graphics”. Not have seen the screen yet, I can’t give an informed view.

Cheap MacBooks if you’re at school or higher education

Just remember if you’re at school or studying in higher education, you can save a reasonable amount of money by visiting the Apple Store for Education. The MacBook Pro’s have some quite decent discounts, with the 13″ model starting at £940 inc VAT and the 15″ model starting at £1409…

Posted in Apple, MacBook | Comments Off on New MacBooks featuring USB3 – where now for Thunderbolt?

Creating routes for custom WordPress post types…

When you’re creating a somewhat more complex WordPress website, you might want to create some custom routes for any custom post types that you create. Whether this is to maximise SEO or just make the URLs a bit prettier, it’s pretty simple to do. The function below added to your theme function.php file illustrates the general idea…

function sweetapple_rewrites_init(){

    add_rewrite_rule(
        'houses/([^/]*)/([^/]*)/?',
        'index.php?pagename=houses&house_search_type=$matches[1]&house_search_query=$matches[2]',
        'top');
    //
    add_rewrite_tag('%house_search_type%','([^&]+)');
    add_rewrite_tag('%house_search_query%','([^&]+)');
}
add_action( 'init', 'sweetapple_rewrites_init' );

Looking for an experienced freelance WordPress developer to convert your designs into a custom theme? Need help customising an existing theme, theme framework, or creating a WordPress child-theme? Please give us a call on 01380 830224.

Posted in Web Development | Tagged , , | Comments Off on Creating routes for custom WordPress post types…

Create custom Catalog navigation menus in Magento…

Out of the box, Magento will happily give you a quite nice navigation menus of your Catalog Categories, including drop-downs for sub-categories.

You also get a number of utility classes added to the individual list items, such as ‘level0 nav-6 level-top’ which enable you to do some tweaking. However the ‘nav-6’ class unfortunately just refers to the position in the menu; so if you rearrange your Catalog categories, the classes changes. This makes it unsuitable for adding Category specific styles to your main navigation. So what can you do if you want to be able to add specific styles to individual Categories?

If you look in the method Mage_Catalog_Block_Navigation::_renderCategoryMenuItemHtml() you’ll find the code that actually renders the menu item. You’ll also find an array called $classes defined. The code below will add cat-13 to the menu item representing the Category with an ID of 13. Obviously I don’t advocate editing the core file, so make your own /local or override it in your own module…

$classes[] = "cat-" . $category->getEntityId();

You could easily extend this methodology to enable the Store Admin to add custom classes or css to the navigation menu by adding a custom field in the Category Admin interface. But for now your front-end developer can now easily target individual list items as they see fit…

Looking for a freelance Magento developer? Give Sweet-Apple a buzz on 01380 830224 -we’d love to help you get your e-commerce website started…

Posted in Magento, Uncategorized, Web Development | Tagged , , , | Comments Off on Create custom Catalog navigation menus in Magento…

New website completed for Devizes based bathroom designers

We recently been working with Aqualis Bathrooms Ltd. Based in Devizes, Wiltshire, but working all along the M4 corridor, London and beyond,  they specialise in the design and installation of luxury bathrooms, wetrooms and stone floors. Like many companies, they’ve organically grown over the years and now find that their word-of-mouth reputation for excellence has spread beyond their traditional core of home-owning customers, through to architects and property developers.

We provided copywriting, design and development services. WordPress was used as the CMS, which enabled us to quickly add media galleries, refresh content quickly and easily, plus provide the client with a platform to let them rapidly add search engine friendly content when needed.

Designers of luxury bathrooms, wetrooms and stone floors, Devizes, Wiltshire

Posted in Web Design, Web Development | Tagged , , , | Comments Off on New website completed for Devizes based bathroom designers