Posted by & filed under Code.

I will be soon do a post on how to create your own custom menu. But what I have created is a function that I made whilst working out a way to add images instead of text to a menu item or adding images to an menu item.

There is a way to add a class to a specific menu item and that is if you click “Screen Options” on your Menu Page you can see “CSS Classes” this will allow you to add a class to a menu item. But if you are wanting to do this dynamically then it is hard due to WP not having a function to do this as they built it into the update of menu items. However, I have extracted the code that does this so that I could then easily add classes to a menu item in my theme if I wanted to. So here’s the code.

function add_menu_class($menu_item_db_id, $class) {
	$class = array_map( 'sanitize_html_class', explode( ' ', $class ) );
	update_post_meta( $menu_item_db_id, '_menu_item_classes', $class );
}

All you need is the menu item ID and the class you want.

Posted by & filed under Code, Wordpress.

So I have been working hard on getting some updates on the plug-in. However, I spent most part of last night and today trying to get the emails feature working. The email feature was to allow you to email a ticket, message or a not to an email which the system would then post for you. It will only allow you to get emails from certain emails that you can specify so you don’t end up with spam posts like you can get with WordPress’s own Post via Email.

To do this feature I wanted to use a PHP function called IMAP_OPEN which on my testing server worked. I was happy as I was getting the emails I wanted until I uploaded the plugin to my test WP on my live server and it was getting a connection refused no matter what I was doing and even WP’s own system wasn’t working. So after speaking to the third Support technician at HostGator I was able to get the problem sorted as apparently there were some conflicts.

Now that I have that sorted I can finally carry on with the plugin. I have also created a jQuery plug-in that creates HTML5 Desktop Notifications, I am hoping to integrate this with the plug-in. I am hoping that I will be at a point in a few days that I can actually start created some of the template side, however, I am going to find creating a nice design to use very hard unless I can find a nice designer to help me out.

Posted by & filed under Code.

I have created a jQuery plugin  that will allow you to easily add HTML5 notifications to your site.

What this plugin does is allow you to create a notification.

The notification API is still very limited so at the moment there are two types normal and HTML. HTML allows you to show a website (basically its like an iframe) but normal allows you to have an icon, title and body, like the image above. If you want to style it then you need to use HTML as you can’t actually style the notification currently and I hope that they soon will allow you to at least make it so that you can change the way it looks a bit.

The top bar shows your Domain or URL, This too can’t be altered from what I have seen. So to be honest these can’t really do much over than they can appear out of the window.

So to the plugin. I have added all the options that I could think off and there really is not a lot.

  • icon – This is the icon that appears in normal on the left. (normal)
  • title – This is the title that gets made bold. (normal)
  • body – This is the content that you can add, some browsers may strip tags I haven’t fully tested this out as of yet. (normal)
  • timeout – This how long you want the notification to be on show. (both) (default 5000)
  • sticky – If this is set to true then it will ignore timeout and will keep the notification on until user closes it. (both)
  • id – This is used to identify the notification that is being shown. (both)
  • type – This is so that you can define which notification you want. (both) (default normal, [normal, html])
  • url – This is where you put your address for the HTML notification. (html)
  • dir – This is for the direction of the text shown in the notification. (both)

Those are the options but I have added four events with them that you can use:

  • onClick
  • onShow
  • onClose
  • onError

As you can see there is not a lot.

Example:

<!DOCTYPE html>
<html>
<head>
	<title>Desktop Notification Test</title>
	<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
	<script type="text/javascript" src="jquery.desknoty.js"></script>
	<script type="text/javascript">
	$(function() {
		$('button#noti').click(function(){
			$.desknoty({
				icon: "http://www.google.com/landing/chrome/ugc/chrome-icon.jpg",
				title: "My notification",
				body: "Woot this is awesome"

			});
		});
		$('button#noti-html').click(function(){
			$.desknoty({
				type: "html",
				url: "http://www.google.co.uk/",
				sticky: true
			});
		});
	});
	</script>
</head>
<body>
<button id="noti">Call notification</button>
<button id="noti-html">Call notification (HTML)</button>
</body>
</html>

When calling the plugin it has to be in an event like click otherwise the API won’t actually do anything.

Demo

Download Link

Posted by & filed under Code, General, Wordpress.

I have not posted for a bit but I have been working on a new WordPress plugin. The plugin is currently called SB Project. The “SB” being my initials, but this will soon likely to change. What this plugin does is turn WordPress into a project and ticket management software. I first decided to do this as the one I use at work was not doing what we needed it to do and the new version of it that had been taken over by Woo Themes was $100. So I decided to create my own that would allow use to do much more.

So currently what I am wanting to get ready before it’s first launch is:

  • Create tickets
  • Create projects
  • Tickets to have extra data like priority, timeline and who is in control etc.
  • It needs to be able to have mail capabilities like mailing when there is a new reply. But also to be able to receive emails for new posts.
  • I have currently got other things working like a full take over of the Dashboard to have widgets that are useful to the plugin.
Because I am doing this a plugin and not a theme like Woo Themes does. It means that the template is more easily to do as you can download the plugin which I will have a pre-set theme created to go with it but you can create your own design without messing the plugin up.
To go with the themes I will be creating some widgets so you could display extra bits of information.
I still have a lot of work to do before I am ready to release it but hopefully this will be something that could be used by many people.

Posted by & filed under Code, Wordpress.

This week I am wanting to show you something very useful. If you are like me you may do many posts and schedule them to be posted. What if you wanted to display your up and coming posts to the users so they know what is to come and when. Well you can very easily.

 

   1:  <?php
   2:  $my_query = new WP_Query('post_status=future&order=DESC&showposts=5');
   3:  if ($my_query->have_posts()) {
   4:      while ($my_query->have_posts()) : $my_query->the_post(); ?>
   5:          <li><?php the_title(); ?> – <?php the_date(); ?></li>
   6:      <?php endwhile;
   7:  }
   8:  ?>

 

So what have we done? Well this is simple we have used the WP_Query class which allows us to get all the future posts and we have limited to 5, then we have done the simple loop that is the same as the one we always use.

Inside the while loop we can display them however, we want. I am just showing a very simple way of doing it.