Skip to content

wordpress: functions to do stuff there way, but what about my way?

So with all this recent playing with wordpress that I’ve been up to, the more and more that I find my self saying ‘This was not designed for me was it?’ Sadly the answer tends to be ‘nope’, but it’s all in PHP so I can monkey with what ever I want to.

GOAL:

  • respect the page order value
  • nested list of links to pages for a nav
  • system that allows me to define the HTML
  • filter list down to only show pages where a custom feild ‘display’ = ‘nav’ (allows me to allow the page to decide where it shows up)

HOMEWORK:

  • get page hierarchy() will not work, as it returns a flat list, thus looses context
  • wp list pages() will not work as it does not allow for custom HTML and does not respect the page order stuff as written in the docs (weird, I know!)
  • crap, I have to write my own

SOLUTION:


<?php
#should we be displaying things here?
function display_is ($p) {
    return ( get_post_meta($p->ID,'display',true) == 'nav' );
}
#does the parent id match? (there has to be a better way then writing to globals?)
function ppid_is ($p) {
    return ( $p->post_parent == $GLOBALS['DSP_current_post_parent'] );
}
#display the pages at this level (RECURSIVE)
function display_sub_pages ($pid, $class) {
    $GLOBALS['DSP_current_post_parent'] = $pid;
    $kids = get_posts( array(
                     'numberposts' => -1,
                     'post_parent' => $pid,
                     'post_type'   => 'page',
                     'orderby'     => 'menu_order',
                     'post_status' => 'publish',
    ) );
    $kids = array_filter ( $kids, 'display_is' );
    # this next one is retarded, but some how needed??? apparently get_posts(post_parent) doesn't work?
    $kids = array_filter ( $kids, 'ppid_is' );
    if (count($kids) > 0 ) {
       printf( "\n            <ul class=\'%s\'>\n", $class );
       foreach ($kids as $p) {
          printf("               <li class='%s' >\n", $p->post_title);
          printf("                  <a href='%s'>%s</a>\n", get_page_link($p->ID), $p->post_title );
          display_sub_pages($p->ID, "_$class" );
          print  "               </li>\n";
       }
       print     "            </ul>\n";
    }
    $GLOBALS['DSP_current_post_parent'] = '';
}

# kick start the process by starting at 0, then dig for sub-pages
display_sub_pages('0','nav');
?>

Now I can have my own HTML, I have a clean recursive call to build the entire tree (, the classes know how deep they are, in short it fits everything that I wished the default one had. It’s not the cleanest code I’ve done, my PHP-fu is rusty, sorry, apart from that, have at it kids. Swindle the code if you need something like this, comment if you found something broken.

Overall lessons learned:

  • PHP callback’s sucks
  • I always forget how stupid it is to just print HTML in your code untill I am forced to get back to it
  • I’m not Wordpress’s target demographic, I guess it’s a good thing for the masses, but it kinda gets to me that there are not hooks for things that I think are simple and obvious.

yes we can, yes we did

image by BohPhoto

So after a some what surprisingly short evening we have entered an era of what appears to be revived hope. It was very interesting to compare the two speeches between McCain and Obama. Both were sincere, honest, and to the point, qualities missing from the public face of both campaigns for a while. I was very pleased with both of the candidates though.

I really have to hand it to McCain, he seemed much more him self tonight, gave a good speech that I could connect with. The toughest thing I have to criticize about his speech was mostly the crowd, he riled up a hornets nest and now has to sit with it. But thats going to happen with any campaign.

John McCain’s Concession Speech in Phoenix

Though it was Obama’s speech that really floored me, it was like no other acceptance speech I can remember, the man has a way with words. He gracefully let some air out of the balloon saying that not everything is going to happen in the next 4 years. He brilliantly used a preachers technique of repetition to involve the crowd (”yes we can”). He used Regan’s ‘Beacon on the Hill’. He echoed Carters speeches telling the americans that we’re going to have to cut back, and it’s going to hurt. He spoke directly to those who were not in the crowd and did not vote for him, he has more of a mandate then Bush ever did (well one could argue post 9-11…) and yet reaches out to every one. He speaks of the worries of the nation, what’s on peoples minds. He’s a very tangible commodity, he’s striving to get us to a point where we can talk to the person across the street, no matter what campaign sign is planted in there yard.

Barack Obama’s presidential acceptance speech in Chicago’s Grant Park [MP3]

I see much of Carter in him, I just hope that it can last. Carter was a one term president because he tried to do too much too fast, was to arrogant too early, the job ended eating him alive. Carter’s legacy has been wonderful, he really found what he was good at, it just was not president. I hope that Obama is really the man for the job, if he can pull together a good team as well as he pulled this nation together then were good, I see a great future before us.

That said, for this to work, we need to all be on the same boat. You don’t have to like it, you can grump if you want, but you have to be paddling in the same direction. The thing that I worry most about with tonight swing, is that we’ve swung too far, that were going to push people away that we really need, there were going to throw the people that grump over board, instead of trying to hear them out. I don’t see this as a problem that Obama caused, but it’s one he will have to deal with, and deal with quickly, before it gets out of hand.

“Good night and good luck”

Election map: another one

NYT’s election map, down to county, (just the swf to view biggie size)

election coverage via google

Other sources that I’m going to be following tonight:

mini distractions: twitter via curl

So there are many posts out there on how to use curl to post to twitter, so when in need of a mini distraction, do something that some one else has already done, a CLI twitter poster.


#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Std;
use JSON;

my $opts = {};
getopt('up',$opts);

die 'I need a username' unless $opts->{u};
die 'I need a password' unless $opts->{p};

my $status = join ' ', @ARGV ;
$status =~ s/ /+/g;

die 'I need a status' unless $status;
die 'status is too long' if length $status >= 140;

my $cmd = sprintf(
q{ curl -s -S --basic --user "%s:%s" --data-ascii "status=%s&source=right+here" "http://twitter.com/statuses/update.json"},
$opts->{u},
$opts->{p},
$status,
);

my $ret = from_json(`$cmd`);
print "Posted\n" if $ret->{id};

not the cleanest code I’ve written all week but it’s a start while I wait for ruby to install and then try it all over again.

long story short git > svn

So at work I use svk, I love svk, I’ve been able to convert half my co-workers to use svk, svk makes my life very easy while still playing with the other half of the office that still uses svn. We are kinda locked in to svn because of that half of the office. It’s not a bad thing, it’s just the way things are. And honestly I’ll take svn over nothing any day.

But that said, git is rocking my socks. In a few hours of me stumbling thru the docs and asking questions on irc (#git on irc.freenode.net) I now have a dev and live version of the site as seperate self-update-on-push repo, and a local repo on my lappy that has a branch for dev, master to live. Yes it’s just that easy. I could write up some bad rendition of an already exiting explanation, or I can spare you the time and just give you the links.

  1. FAQ on why non-bare is bad, yet it has a link to the hook to allow for a self-update-on-push repo
  2. git for any one with svn experence
  3. hooking up two remote repos to one local repo

Gripe about the internets

Ahh the wonder that is Google Reader, it brings me such little nuggets of the internet like this LA times article about what you should use in the kitchen. I don’t know who there really trying to talk to? Some of it is spot on and silly, other times they are trying to hard to be something fancy. It kinda got under my skin:

  • Mortar and pestle, optional, it’s nice, I use mine, but I could easily do with out one.
  • Good corkscrew, I’ll agree that its nice to have good tools but I would get one that looks like this. More sturdy and can be used as a can opener. I think that I got mine for $1 at goodwill.
  • Instant-read thermometer, optional, if you roast big hunks of meat then it’s going to be good to have one around. But really, if you cook enough you’ll get the hang of things and will not need one. If your going to spend your money one one get one with a remote digital readout with an alarm so you can go do something else while that bird roasts.
  • Good dried pasta, buy cheap or make your own… really it’s easy. Pasta = flower(whole wheat if you got it) + egg(if you got one) + oil(olive) + water. Really, it’s just that easy.
  • Small kitchen scale, if you bake a must, if you don’t, well don’t bother.
  • Heavy-duty roasting pan, really? If you find your self cooking a large turkey more then 2 time a year, sure. If you find your self cooking for parties of 10+ at least once every month of the year, sure. Other wise, skip it.
  • Expensive red wine vinegar, exactly, who are you trying to sell this to?
  • Mini food processor, bingo
  • Expensive nonstick skillet, I agree you never need to spend more then $30 on this necessity, go cast iron, 10in skillet ($20 new, $5 at thrift store), it will out live you.
  • Expensive knives, expensive is subjective, find a good knife (mine $20 for a set of 3, look good feel great.) but then you have to keep it good. Get a nice sharpener and a good hone.
  • Big red wines, sure indulge, life is short.
  • White truffles, I am so not the target demographic
  • High-quality coffee, or am I?
  • Dutch oven, yup, if your going to spend your money, spend it on something you can use.
  • Whole vanilla beans, it really depends on where your going to use it, cookies pass. The oven will eat it alive, ice cream, I’ll take two scoops please.
  • Saffron, if you really really want, sure, but only buy as much as you need.
  • Microplane, great for hard things (nuts, parm, knuckles).
  • “Larousse Gastronomique”, your just trying to impress your friends.
  • Toaster, torn, they do make good toast, but they don’t do much else… now my stove also makes really good toast, just not as fast.
  • Flavored salts, I agree, now your really trying to impress your friends.
  • Crème brûlée torch, exactly, not quite a blow toarch, not quite a lighter, not good for much else… well candles I guess.
  • Filet Mignon, or you could just go veggie.
  • Crêpe pan, a good kitchen tool needs to be a multi-tasker.
  • Fondue pots, if you want good fondue go out for it ( I highly recommend the Berlin Inn).

So while were on the subject….

My Essentials:

  • Skillet, pref cast iron.
  • Dutch Oven/Chicken Fryer, only diff are the handles
  • 2 knives (1 chef, 1 paring)
  • Butcher Block(mine)
  • silicone spatula
  • sink
  • stove

The runners up

  • Stock Pot
  • ladle
  • serving spoon
  • bamboo spatula
  • pressure cooker
  • ‘pizza’ stone

The power of doing what everyone else is doing.

So my big project at work the past few weeks has been moving us from very ad-hoc svn setup that did not allow branches to a nice new clean repo that does. I’ve learned a lot about what svn likes and what it doesn’t I feel that I have a very good understanding of the admin aspect of svn. All handy skills to have under the belt.
Though thru all of this I have really grown to love what you can do with svn, but have really started to admire all the things that git allows you to do. This was hard enough to get everyone else even on board enough to start the project so I don’t see us moving to git any time soon but now that we have one single repo git svn is at least an option for anyone who wants to play.

What is it about blogging platform conferences?

[mini rant]
I held out hope for #wordcampdx, I think that theres still some promise, though it’s all going to be in the sessions. From now on I think that I’m going to skip every keynote as there always one ritual away from a cult? I’ve been to many tech confrences, the only two that have really creep-eeed me out have been Drupalcamp and now wordcamp. I think that they evangelizm is all with good intent, and I’m not trying to be cynical, but think about it. Everyone who has payed $10, and showed up @ 840, so I think that we can assume that there is some level of love for the topic of the day, wordpress(wp). I don’t need to be sold on how cool wp is, I’m already here.
I’m still holding out hope for the sessions, but so far things have gotten off on the wrong foot for me.
[/mini rant]

A whole slew of things to write about, I’m just not going to.

See thats the problem with this whole “inbox zero invades the rest of your life, thanks Merlin” Lifestyle change thing, you start making lists and getting things that need to get done and make a bunch of lists of everything else. So we all now know that blogging is not at the top of the ‘what I want to do with my day today’ list… sorry folks, your just don’t scream loud enough as everything else in my life.

So what wonders do I have for you today, toys and tools…. or rather toy and tool, you figure out what link goes in what category.