Browsed by
Tag: php

Update March 2014

Update March 2014

I thought I would give an update on my blog as it has been a while since I did so!

A major project that I have been working on for almost 6 months now is about to go live. I am looking forward to releasing it next week and showing the world what me and (now) a team of developers have created.

Recently I also managed to get a bit of spare time to start developing a side project in php. The main goals of this are really to get back into programming as I have taken some time away from that side of Software Development for a while. I thought it would be a nice time to get into some of the UX aspects of projects by playing around with ajax and javascript some more. I find it really rewarding when you can show something visual, even if the back-end parts take a lot longer to plan and develop and are actually, personally more satisfying to complete.

This side-project is coming together slowly as I dedicate more and more time to it. I look forward to releasing it when it is presentable, but it is a database tool that I would find very useful at least, and hope that many more would do so too.

I have another side project that I really want to complete, but find myself not having nearly enough time, patience etc… to actually get anywhere with it. That is to edit down a video from my 25 day cycle across Europe that ended just over 5 months ago! There is a lot of footage which I have whittled down to about 3 hours, but there is a lot more that needs to be cut, let alone the masses of editing that needs to be done before I can release it. I am hoping to dedicate 5 hours on it a week in order to chip away at it in a structured fashion, rather than attacking it randomly as I have been doing.

Otherwise, there are grand plans for another iPhone game in the future. The recent success of Flappy Bird and 2048 are really inspiring to see. Not to mention the WhatsApp acquisition by Facebook. On top of all this, there may be another project to manage that might get funding thanks to a friend’s application to some grants!

All very exciting, not to mention the “Ride for the Living” bike ride that I am helping to organise in June from Auschwitz to the JCC in Krakow.

Creating a WordPress Theme from Scratch: Adding Menus

Creating a WordPress Theme from Scratch: Adding Menus

As discussed in previous post, functions.php is automatically included in the processing of a theme. This is therefore the best place to add default settings that you want to a theme, as well as helper functions.

To make sure that a function is called on the initialisation of a theme you should use the following in the functions.php file:

function add_menus(){
// Do Stuff Here
}
add_action( ‘init’, ‘add_menus’ );

In order to register the menus for your theme you need to use: register_nav_menus with an array of ‘slugs’=>’descriptions’:

register_nav_menus(
array(
‘main_nav’ => ‘The Main Menu’,
‘footer_nav’ => ‘The Footer Menu’,
)
);

This will do two things.

1) It will add an ability to edit menus on the theme once activated:

Adding Theme Settings

 

It will also add all the menus that you have specified to the list of possible menus that you can use:
Menus of a Theme

 

Now to actually display the appropriate menu you just need to call wp_nav_menu(‘slug’).

So our example would be wp_nav_menu(‘main_nav’); or wp_nav_menu(‘footer_nav’);

This will print out whatever menu you have in those drop downs above.

However if one isn’t selected it seems to still show the menu with Home and About. So I created a wrapper in my functions.php as so:

function get_menu($menu){
$locations = get_nav_menu_locations();
if ($locations[$menu]){
wp_nav_menu(array(‘theme_location’=>$menu));
}
}

Now I simply call get_menu(‘main_nav’); and it will either show nothing if the menu is blank or it will be the actual menu selected.

That is it for menus for now. Remember to check how WordPress outputs the menus and change the CSS to suit how you want it to. (e.g. by default it uses menu-top-menu as the class). Or you can use a custom class  when calling wp_nav_menu():

wp_nav_menu( array( 'theme_location' => 'extra-menu', 'container_class' => 'my_extra_menu_class' ) );
Creating a WordPress Theme from Scratch: Getting Started

Creating a WordPress Theme from Scratch: Getting Started

There are actually only two files that you need to get a basic theme up and running: index.php and style.css. If you add these to a new theme folder (wp-content/themes/new-theme-dir/) then you can choose your theme from the dashboard (Appearance->Themes):

New blank theme

 

To populate this data with the details of your theme, you need to create an initial comment in the style.css file like so (I called my theme Raul just because…):

/*
Theme Name: Raul
Theme URI: http://www.dezco.co.uk/
Description: A nice clean news looking design.
Author: Robert Desmond
Author URI: http://www.dezco.co.uk/
Version: 1.0
Tags: responsive, white
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/

Detailed Theme

To add a screenshot of how you want your theme to look you simply need to add a file called screenshot.png to your theme directory (dimensions 600×450). (I took a picture of my drawing on paper until I would finally get a real screenshot!)

Updated Screenshot

There you go! You now have a theme that you can activate although you are probably a fair way from making it look good!

Next steps: Structure of a Theme…