WordPress.org

Support

Support » Themes and Templates » Adding custom Taxonomy to post meta

Adding custom Taxonomy to post meta

Viewing 5 replies - 1 through 5 (of 5 total)
  • I don’t have perfect answers for all your questions, but you’ve put so much effort into this and asking about it that I can’t stand to see you go unanswered.

    1. I think those variables with the percent sign and number preceding them are placeholders. Take a look at the section “Messages with Placeholders
    2. It looks like $utility_text is just a variable set on line 58 of your pastebin code.
    3. The printf function is a lot like echo in that it outputs text to the browser, but printf allows you to format the text. Have a look at the PHP manual here. What the code you have does is set the formatting string to the $utility_text using the placeholders in consecutive order, so %1$s would be $categories_list, %2$s would be $tag_list, etc.
    4. It’s hard for me to answer this one, because it depends on when you want your taxonomies to display. It seems like you would always want them listed if they exist, wouldn’t you? If that’s the case, you could construct an independent conditional statements for them and add them in the format you desire if they aren’t empty.
    5. I haven’t seen underscores in PHP in a long, long time, and I have no idea why they are using them here. It used to be used to designate private functions, but the way you did it; i.e., without the underscore, is correct for current versions of PHP, I believe.
    6. I think you understand the get_the_category_list function correctly, it’s their use of the underscore that’s throwing you off. They’re basically just using a comma and space for the separator.

    There are couple of things you might consider. First is that PHP has some really handy array functions. One use would be to get that “and” in there that you want. The get_the_category_list and others that return comma-separated strings can easily be used to create arrays using the PHP explode function, which you can then count using the count function, and iterate through using the foreach construct. Using a counter, you could add the ” and” prior to finishing the string off with the last value.

    Since your experimental code is also redundant, you could even construct an array using the variable names for each group, then use a foreach loop to handle each pair. That would make your code much more efficient and easier to maintain.

    Thanks for the reply… it appears that the __() is being used for putting the translation in from the .po and .mo files. On of your links showed me that: http://codex.wordpress.org/Translating_WordPress

    It would seem that with as popular as custom meta and custom taxonomies are that there should be a plugin for adding custom meta to content.phpand content-single.php

    Ah, good catch on the underscores. I missed that. Good to know.

    Here I thought you just wanted to roll your own. I’m surprised there aren’t plugins that handle it too. When you’re done with this, you could tackle writing one. : )

    Is there a hook I could use? cause I would rather do this via a plugin rather than through a child theme. It might be more code but there is the pro of transferability after a theme switch.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Adding custom Taxonomy to post meta’ is closed to new replies.