Jack McIntyre » Code http://jackmcintyre.net Mostly talking about beer Sat, 25 Jun 2011 08:01:12 +0000 en hourly 1 When wp_list_pages() can't do it… http://jackmcintyre.net/when-wp_list_pages-cant-do-it/ http://jackmcintyre.net/when-wp_list_pages-cant-do-it/#comments Wed, 06 May 2009 21:31:00 +0000 Jack http://jackmcintyre.net/?p=49 I just fixed up my projects page to use a custom template rather than free text editing. To do this, I wanted to use wp_list_pages(), however this does not give you the ability to easily add text inside the <li>, but outside the <a>. My solution was to use get_posts(), and a custom loop instead. The code below is the main customisation in my new “List Child Pages” template.

1
2
3
4
5
6
7
8
<?php
global $post;
$myposts = get_posts('post_parent='.$post->ID.'&orderby=menu_order&post_type=page');
foreach($myposts as $post) : ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>: <?php echo get_post_meta($post->ID, descript, true) ?>
</li>
<?php endforeach; ?>

In this example, get_posts() is returning all posts (or confusingly, pages) that have a post parent of the current page (ie they are sub pages), ordered by the wordpress menu order, and of type “page”, as opposed to post. You can get your own attributes from the codex page. Once get_posts() is set up, each post is echoed in a list. This is where the custom field gets added, using get_post_meta(). This solution is far simpler and neater then any method I saw of modifying wp_list_pages() to include a custom field. I don’t have much experience with custom loops, but I can’t see why there would be too many restrictions on where they can be used.

]]>
http://jackmcintyre.net/when-wp_list_pages-cant-do-it/feed/ 0
How to add macros to the Excel 2007 Ribbon http://jackmcintyre.net/how-to-add-macros-to-the-excel-2007-ribbon/ http://jackmcintyre.net/how-to-add-macros-to-the-excel-2007-ribbon/#comments Thu, 02 Apr 2009 18:20:00 +0000 Jack http://jackmcintyre.net/?p=56 As much as I dislike using Microsoft products, sometimes, you have no choice. In our work with salesforce.com, the Excel Connector is a huge time saver. We use it for a number of things, and it is far superior to the data import functionality of salesforce.com. In the upgrade from Office 03 to Office 07, custom toolbars were lost. I spent quite a while looking for the ‘custom ribbon’ in Excel 07 – it does not exist. Here is what you need to do to build a tab in the ribbon, add buttons for your macros, and embed both the customisations and the macros in an add-in (for deployment). I still have a few little changes to make, but everything is working with it set up like this.

  1. Create a new workbook in Excel
  2. If you do not already have your macros recorded, do that. If you do have them recorded, go into VB mode and copy the module(s) into your new blank workbook. Save the workbook as <add-in name>.xlam
  3. Download and install the Custom UI Editor Tool
  4. Start the custom UI Editor, and open your .xlam file. Now you can start customising the appearance of the ribbon. My code looks like this at the moment:
  5. Once you have edited the xml for your ribbon customisations, save and exit the Custom UI Editor Tool, and start excel. Next, activate your add-in. That code should get you something that looks like this:
  6. Here is an example of how each of my macros is coded. Note the main macro, and the smaller one above that references it:
  7. Once you are happy with it, you can distribute your .xlam file, complete with macros and ribbon enhancements. All the recipient needs to do is activate the add-in.

To be completely honest, I don’t fully understand the reason for using callbacks in macros. I believe it is so that you can continue referencing the original macro elsewhere (without the “control As IRibbonControl” bit). The ribbon has copped a lot of hate since its launch, but I don’t think it’s all that bad. I’m actually getting used to it. While the process of customising it is challenging (to say the least), I think the results are pretty professional. You have far more power than is demonstrated in my example. It looks like you can get pretty creative in your ribbon design – there are plenty of options for button types, images, etc on this page. It took me long enough to get it this far though :)

UPDATED: Here is a template to use in the custom UI editor. Replace “onAction” text with callbacks to your macros, and change the label to suit.

]]>
http://jackmcintyre.net/how-to-add-macros-to-the-excel-2007-ribbon/feed/ 1