home

WordPress, Exec-PHP plugin and Pages

That was an awfully long sidebar over there, no? I’ve been holding out against changing the display of archives and categories to drop down menus, meaning to investigate the use of (WordPress specific) php in posts and pages, thinking I’d move them off the front page entirely, giving more prominence to the blogroll.

Enter Soeren Weber’s Exec-PHP plugin:

The Exec-PHP plugin allows <?php ?> tags inside your Wordpress posts and pages to execute the code inside of it just like you normally write and run code inside of any PHP file.

I installed it earlier today, activated it via the WordPress plugins page and can now use php code everywhere!

I’ll quickly document what I did so that I can refer to it in the future but I can’t be the only person who’s wanted to do this but not quite gotten around to it? In the meantime, apologies to non WordPress users, you might like to wait for today’s next post, “Wimmin wot I admires”.

First up, I created a new Page called Archives Test, then opened up a copy of sidebar.php and copied the code that displays the H2 heading “Archives” and the php that displays them by month:

<h2>< ?php _e(’Archive’); ?></h2>
<ul>
< ?php wp_get_archives(’type=monthly’); ?>
</ul>

and pasted this into the new Page and bingo! We have a page showing the archives. It needs tidying up and formatting of course but the Exec-php plugin makes it so easy to display that php code.

You do exactly the same if you want to display, for example, Categories:

<h2>< ?php _e(’Categories’); ?></h2>
<ul>
< ?php list_cats(0, ‘’, ‘name’, ‘asc’, ‘’, 1, 0, 1, 1, 1, 1, 0,'’,'’,'’,'’,'’) ?>
</ul>

Now, that default page theme includes the sidebars (with archives, categories, blogroll and sideblog etc.) so I need to create a new Page template that just has the banner for easy access back to the home page.

But wait! You might be using a theme that includes additional Page templates - check to see if you have more than the default option in the drop down menu under Page Options (you can see a screenshot here).

I adapted this (slowly being improved for accessibility issues) layout from ClemensRelaxation theme and he included two Page themes which I’m going to tweak a little. I won’t write about how I do that (kludge, kludge and more kludging) because you couldn’t want a better tutorial than the one on the WordPress Codex - Creating your own Page Templates.

In the meantime you can now access the archives from here. Phew!

4 Responses to “WordPress, Exec-PHP plugin and Pages”

  1. Knock Knock Mary
    March 7th, 2006 16:56
    1

    Belly, Belly interesting. I’m reinventing my blog on Blogger.com and have all kinds of new options. Our little hamster run server is getting old and worn out, thus the decision to move - eventually.

  2. Em³
    March 7th, 2006 19:30
    2

    I’ve got PHP Exec and I know it’s the sort of thing that sounds useful.

    However, I’ve never needed to put PHP code within a post. Where I want to do “clever” things (e.g. my image display script), I just create a page template.

  3. Gordon
    March 8th, 2006 10:31
    3

    Hmmm interesting but I’m still not sure when I’d use it…

    Archive wise I’m interested in this though: http://www.sonsofskadi.net/index.php/extended-live-archive/

    Neato stuff. Ain’t WP great!

  4. daisy
    March 8th, 2006 11:14
    4

    Oh Mary, are you really going with Blogger? Wouldn’t a nice WordPress install be easier? Or how about the wonderfulness that is Blogsome.com (free hosted WordPress) ?

    Em, I’ll be picking your brain (again) later this week ;-)

    Gordon, ELA sounds full of ajaxy scrumptiousness, have bookmarked under “to be investigated” - thank you!

Leave a Reply

For added zing, you can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

But you can also just type in the box and hit the Submit button. Easy peasy lemon squeezy.

Your email address is not displayed and will NEVER, EVER be shared with any other party. We hate spam mail as much as you do.

Spotlight on...

Delicious links

These links are updated frequently thoroughout the day. Should you miss any they're all stored on my Delicious pages.

What I'm listening to

\n\n