﻿<feed xmlns="http://www.w3.org/2005/Atom">
  <title type="text" xml:lang="en">PHP</title>
  <link type="application/atom+xml" href="https://d.moonfire.us/tags/php/atom.xml" rel="self" />
  <link type="text/html" href="https://d.moonfire.us/tags/php/" rel="alternate" />
  <updated>2026-07-22T17:35:48Z</updated>
  <id>https://d.moonfire.us/tags/php/</id>
  <author>
    <name>D. Moonfire</name>
  </author>
  <rights>Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International</rights>
  <entry>
    <title>WordPress custom taxonomies</title>
    <link rel="alternate" href="https://d.moonfire.us/blog/2012/07/09/wordpress-custom-taxonomies/" />
    <updated>2012-07-09T05:00:00Z</updated>
    <id>https://d.moonfire.us/blog/2012/07/09/wordpress-custom-taxonomies/</id>
    <category term="programming" scheme="https://d.moonfire.us/categories/" label="Programming" />
    <category term="php" scheme="https://d.moonfire.us/tags/" label="PHP" />
    <category term="taxonomies" scheme="https://d.moonfire.us/tags/" label="taxonomies" />
    <category term="wordpress" scheme="https://d.moonfire.us/tags/" label="WordPress" />
    <content type="html">&lt;p&gt;One of my short term goals is to migrate a DokuWiki site over to WordPress. The decision to do this was somewhat complicated, but it came down to me not wanting to maintain too many systems. DokuWiki is great for what I used it for, but I'm maintaining seven websites now and I need to reduce my overhead since I need to focus on other things (writing, programming). I finished the second to last one (&lt;a href="http://nobelpencr.org/"&gt;The Nobel Pen&lt;/a&gt; on Saturday and started into the one I've been stalling on.&lt;/p&gt;
&lt;p&gt;&lt;!--more--&gt;Migrating my byline is actually a (relatively) major task. There are about a hundred short stories, a number of novels, and quite a few essays. In addition, almost everything is arranged into way too many taxonomies that make sense for that byline but not for anything else I do.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;You might wonder why in the world I have so much tagging. Well, when I burn out I usually start cleaning. Plus, I wanted to see which views I wasn't writing about so I could. It ended up being a few months effort spread out since 1993, so it doesn't feel like I spent that much time on it.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;WordPress handles custom taxonomies very well, but it needed some custom work. I could use a plugin to manage it, but after trying a few plugins, I decided to do it the "hard way." Now, the general suggestion is to do it in a custom theme, but I decided to create a plugin to manage it (local-sitename). This way, if I change the theme (which I have done twice now) I don't have to move over the taxonomies.&lt;/p&gt;
&lt;p&gt;The basic local theme would go into &lt;code&gt;wp-content/local-sitename/local-customizations.php&lt;/code&gt;. It needs a comment block which dictates what shows up on the plugin list inside WordPress.&lt;/p&gt;
&lt;pre&gt;/*
 Plugin Name: Local Customizations (sitename)
 Version: 0.0.0
 Author: D. Moonfire
 Description: Adds in the site-specific customizations for http://sitename/.
*/
&lt;/pre&gt;
&lt;p&gt;The plugin file also has a hook which is called when the plugin is activated for a given site.&lt;/p&gt;
&lt;pre&gt;// Add in a hook to add the taxonomies and categories.
add_action("init", "sitename_init", 0);
&lt;p&gt;function sitename_init()
{
// Register the taxonomies associated with pages.
create_taxonomy(&amp;ldquo;format&amp;rdquo;, &amp;ldquo;formats&amp;rdquo;, &amp;ldquo;Format&amp;rdquo;, &amp;ldquo;Formats&amp;rdquo;, false);
create_taxonomy(&amp;ldquo;language&amp;rdquo;, &amp;ldquo;languages&amp;rdquo;, &amp;ldquo;Language&amp;rdquo;, &amp;ldquo;Languages&amp;rdquo;, true);
create_taxonomy(&amp;ldquo;magic&amp;rdquo;, &amp;ldquo;magic&amp;rdquo;, &amp;ldquo;Magic&amp;rdquo;, &amp;ldquo;Magic&amp;rdquo;, true);
// quite a few more taxonomies&lt;/p&gt;
&lt;p&gt;// We need pages to have archives so we can use the taxonomies.
$page_type = get_post_type_object(&amp;ldquo;page&amp;rdquo;);
$page_type-&amp;gt;has_archive = true;
}&lt;/p&gt;
&lt;/pre&gt;
&lt;p&gt;The last parameter of &lt;code&gt;create_taxonomy&lt;/code&gt; determines if it is a hierarchy taxonomy or a flat one. For format (e.g., Story, Essay, Novel), it doesn't make sense to have a tree-like structure. But for languages and magical systems (actually most of my taxonomies), I use the parent/child relationship since I kept track of related languages (Romance Languages verses French).&lt;/p&gt;
&lt;p&gt;Creating the taxonomy is pretty simple. I have a helper function to do most of the hard work for me:&lt;/p&gt;
&lt;pre&gt;function create_taxonomy($key, $slug, $singular, $plural, $is_tree)
{
  register_taxonomy(
    $key,
    array("page"),
    array(
      "hierarchical" =&amp;gt; $is_tree,
      "labels" =&amp;gt; array(
        "name" =&amp;gt; $plural,
        "singular_name" =&amp;gt; $singular,
        "search_items" =&amp;gt; "Search $plural",
        "popular_items" =&amp;gt; "Popular $plural",
        "all_items" =&amp;gt; "All $plural",
        "edit_item" =&amp;gt; "Edit $singular",
        "update_item" =&amp;gt; "Update $singular",
        "add_new_item" =&amp;gt; "Add New $singular",
        "new_item_name" =&amp;gt; "New $singular Name",
        "separate_items_with_commas" =&amp;gt; "Separate $plural with commas",
        "add_or_remove_items" =&amp;gt; "Add or remove $plural",
        "choose_from_most_used" =&amp;gt; "Choose from most common $plural",
        "menu_name" =&amp;gt; "$plural"
      ),
      "public" =&amp;gt; true,
      "show_in_nav_menus" =&amp;gt; true,
      "show_ui" =&amp;gt; true,
      "query_var" =&amp;gt; true,
      "rewrite" =&amp;gt; array("slug" =&amp;gt; $slug, "with_front" =&amp;gt; false)));
}
&lt;/pre&gt;
&lt;p&gt;This creates a pretty taxonomy. The new taxonomies show up under the "Pages" menu on the Dashboard and each one shows up on the right of each post. Now, you may notice that I have "page" in two places. Normally, taxonomies aren't associated with the "page" post type. Most of the examples, they have them assigned to custom post types.&lt;/p&gt;
&lt;p&gt;For &lt;a href="http://d.moonfire.us/"&gt;D. Moonfire&lt;/a&gt;, I used a custom post type instead of messing with page. Because of how WordPress works, a custom post type has to have a slug, which is why all my story URLs start with "/fiction/". For the D. Moonfire site, this way okay because I didn't have many links out there and I use a relatively flat story organization. For the other site, which has mostly kept unbroken links based on setting. I've also used much of that structure since 2002-2004, so I couldn't really use the "/fiction/". In this case, I used page directly. I did the same with &lt;a href="http://mfgames.com/"&gt;Moonfire Games&lt;/a&gt; and the projects because of the historical links.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;I try really hard not to break links. Even knowing that not many people visit my sites, I still feel the need for consistent URLs.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;If you go to the website for &lt;a href="http://mfgames.com/mfgames-writing"&gt;MfGames Writing&lt;/a&gt;, you can see taxonomies in use on the right hand side. Clicking on the links brings up a list of pages with that category (say License). To get this to work, I had to use the &lt;code&gt;$page_type-&amp;gt;has_archive = true&lt;/code&gt; line above.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Lovely Problems Starting...</title>
    <link rel="alternate" href="https://d.moonfire.us/blog/2007/08/22/lovely-problems-starting/" />
    <updated>2007-08-22T05:00:00Z</updated>
    <id>https://d.moonfire.us/blog/2007/08/22/lovely-problems-starting/</id>
    <category term="family" scheme="https://d.moonfire.us/categories/" label="Family" />
    <category term="games" scheme="https://d.moonfire.us/categories/" label="Games" />
    <category term="programming" scheme="https://d.moonfire.us/categories/" label="Programming" />
    <category term="php" scheme="https://d.moonfire.us/tags/" label="PHP" />
    <content type="html">&lt;p&gt;Well, things seem to be starting toward a brief spat of annoying things. We came home to find our refridgerator appears to be not working properly. In fact, it is not keeping cold things cold. And, since I like to believe I'm not in a consumable environment, I decided to call on an appliance repair instead of just going out and buying a new one. Hopefully, it is something small and insignificant, or my already taxed bank account will be more taxed.&lt;/p&gt;
&lt;p&gt;Also, I think we changed things a bit too much for our kitties. We want to try toilet training them, but they haven't really gotten going so far. We tried setting up boxes in the bathrooms but they aren't using it yet. I might try a more normal-looking box if I have to go out for a new fridge today.&lt;/p&gt;
&lt;p&gt;One of my lights in my office (1 of 4 + a fan) that is on the switch died last night. It was only a 30 USD lamp, but I like a very well-lit office (1-150 equiv watt florescent, 2-75 equiv watt florescent, and a 5-bulb chandelier, 40 watts each). Haven't gotten the chandelier in florescent mainly because I just recently found small bases for those. Yeah, I like bright rooms, but it hurts to work in dim rooms for me.&lt;/p&gt;
&lt;p&gt;We also moved their cat food. It used to be on the sun porch, which is rather hot and humid. One of our kitties, Trillian, didn't appear to be eating there, so we moved it inside. Now, only one of the cats is eating from it. This morning was the first time I saw Chloe actually eating from it and I had to put her there. Paks (short for Paksenarrion) is the only one who appears to actually be eating from it. I'll buy a new bag of cat food and see if the low allergy stuff rotted on the sun porch (which is possible) or spoiled. Again, if I go out to get a new fridge.&lt;/p&gt;
&lt;p&gt;Other than that, I updated my theme for &lt;a href="http://mfgames.com/"&gt;mfgames.com&lt;/a&gt;. Its a much different them than I'm normally used to, but it was inspired by a few things. One, dark themes require less energy to display than white themes. Yeah, the savings will be about 0.000000001 USD per page, but every little bit helps and I think it is the right direction to go. Also, I thought it had a quaint look to it. Later, I'm going to write some Javascript to change the top part based on the time of day, that way if you visit the site at night, you'll get a night scene or something.&lt;/p&gt;
&lt;p&gt;It also leads into my plans for today (barring the refrigerator): to create a comic updating script to see if I can queue up some of these comics and get ahead. &lt;a href="http://fightertype.livejournal.com/"&gt;Fightertype&lt;/a&gt; has been pressing me to first do ten ahead, then start releasing them. However, my lack of confidence in creating visual arts means I'll be releasing them as soon as I finish, or on a Thursday schedule, whatever is slower. I appear to be reinventing the wheel, mainly because I couldn't find any good comic updating scripts on Freshmeat and it isn't that much work to do something that gives me the features I want: queued updates, script breakdown, comments, and potential language translations. It is unlikely that this will be popular, but it is things I think are important.&lt;/p&gt;
</content>
  </entry>
</feed>
