Portfolio Post Type Plugin

I recently released a plugin on WordPress.org that registers a portfolio post type, related taxonomies, and adds an image when you’re viewing the items in the dashboard.

I’ve held onto to the plugin for a while in GitHub since it’s an easy thing for any developer to build out- but I’ve recently been thinking that a standard plugin in the repository might be beneficial as it could make more themes more portable. (Especially for users of my Portfolio Press theme)

And since I expect people to modify this a bit as well, I wanted walk through of the code.

Plugin Header

[gist id=”62036e1ef1ea6d79318b4c3b0ff9bae1″ file=”portfolio-post-type-gist.php” lines=”1-10″]

Explanation: All plugins need to have basic header data in order to show up in plugin admin page. If you don’t want to get updates to the plugin (I don’t expect many), change the name to something different. Shoot, feel free to change any of this- that’s why it’s being released!

Enable the Portfolio Post Type

[gist id=”62036e1ef1ea6d79318b4c3b0ff9bae1″ file=”portfolio-post-type-gist.php” lines=”12-44″]

This is the basic code needed to register the portfolio post type. I’ve wrapped it all in one function that fires on init. For a deeper explanation of all the arguments ($args) check out the codex post.

Register Taxonomies

Wrapped in that same function I also register two taxonomies for categories and tags. Since that code is long, and basically just a bunch of labels I’ll point you to the actual code on GitHub. If you don’t want taxonomies, you don’t actually need that code.

Use Post Thumbnails

If you want your post type to be able to use thumbnails, you’ll need to register it:

[gist id=”62036e1ef1ea6d79318b4c3b0ff9bae1″ file=”portfolio-post-type-gist.php” lines=”46-47″]

View Thumbnail Images in Column View of Dashboard

For something like portfolio items, it’s nice to see the images when you’re scanning posts in the dashboard. I wrote about how that functionality works in a separate post.

Display a Custom Icon for Portfolio Menus

I was lucky enough to get Ben Dunkle (the designer of the WordPress icons), to make some portfolio icons for me for the first version of this plugin. Now, most plugins use dashicons for custom post types.

Custom Meta Boxes

This plugin doesn’t register any custom meta boxes, but those obviously might be useful if you want to include a link a website, or a purchase button, etc. If you’re interested in doing that- see my post on adding custom meta boxes to post types.

Download

About Devin

I am a developer based in Austin, Texas. I run a little theme shop called DevPress and help manage a WooCommerce shop with Universal Yums. Find me on twitter @devinsays.

36 Responses

  1. Hello.
    I used your cool theme, now i downloaded portfolio plugin.
    I noticed, that strings with “_x” are ignored, when translated.
    for example when I translate:
    ‘name’ => _x( ‘Portfolio Categories’, ‘portfolioposttype’ )
    I still get english version.
    It look like one argument is missing, it should be something like:
    ‘name’ => _x( ‘Portfolio Categories’, ‘CONTEXT’, ‘portfolioposttype’ )
    I changed if for now, but i don’t like to hardcode plugins, can you please take a look at it?
    Cheers
    Jacek

  2. I am a beginning designer, and I am really happy to have found your portfolio custom post type.

    it seems to have all the functionality i want for a main aspect of my new website,

    i need a searchable, functional catalog of images (10000+) with separate categories and tags.

    the problem i am having is that my theme does not have a single.php file, it seems to run through the index,

    it doesn’t work if i make a new single (post) template file, the way it does with my page templates.

  3. Hello Devin! I have a problem using your plugin:
    I created categories into Portfolio but I can’t call them from the theme. I never find the categories by ID or by the name (category_name = categortname). What need to change the theme using your plugin? Thank you very much!

  4. Hello. Thanks for the portfolio theme.
    I’m working whit portfolio theme and plugin and it’s awesome.
    I need to put thumbnails who replaces the “next-previous page” text in the portfolio posts, but i don’t know if it’s possible.
    I would like too to make a page whith all portfolio thumbnails and every thumb linking to his respective portfolio post.
    Sorry but my english is very poor.
    Thanks a lot.

  5. Hello! I’m using your Portfolio Press theme and have now downloaded your portfolio post plugin. I love both of them! The problem I’m having is that whatever image I use as the featured image to show up on the portfolio page is showing up twice on the single portfolio post page. What do I need to do to stop this from happening? What file is this code in?

  6. I’m trying to set up this plugin on my new site (not live). I created an archive-portfolio.php file, which is working. But when I open a category page, e.g. ‘/portfolio_category/example’, WordPress is still using the ordinary archive.php file. Why is this? What do I need to change? Do I need a category-portfolio.php file? (And if that’s the case, why is WordPress using archive.php to display portfolio categories instead of category.php?) Thanks!!

  7. Pedro

    Devin Good night, all right?
    If I want to list the project types that signed up I use the following code

    ”, ‘taxonomy’ => ‘portfolio-type’, ‘walker’ => new Portfolio_Walker ()));?>

    How would I do to Portfolio Categories list, taxonomy portfolio_category?

    Thanks in advance.

  8. suz

    Hi I am using your plugin as part of a theme I am developing. I have setup the portfolio type with several categories and child categories. I have a template page – archive-portfolio.php that is properly being called, however when I select a subcategory the query returns all the portfolio items and not just the posts within the sub category. Can you offer a quick snippet of what the query arguments should look like to only display the category that is selected or called ?

    Thanks
    Suz

  9. Tandarts

    Thank you for the great plugin

    I would like to know if it is possible to rename the portfolio to purchase since I want to use it for my purchase area instead of using it for an portfolio.

    Shou.ld I rename the templates to single_purchase and archive_purchase and create and page called purchase.. (I really have no clue how to do this)

    Thank in return.

  10. Hi Devin,
    I am trying to set up a simple xml-rpc post method using python. While I cannot seem to create a portfolio item remotely, I can create a post and convert it to a portfolio item (using Post Type Switcher). Unfortunately the tags that are associated with the post are lost in translation. Is there anyway to retain that part of the post taxonomy and still have access to the other portfolio features? Or perhaps there is a simple way to rpc in my portfolio items? Thanks for the great work!

  11. Hi — We’re using the plugin for portfolio but the formatting is totally out of whack and we keep getting “illegal string offset” errors displayed on our published pages. Any suggestions on how we might fix this?

    Thank you!

  12. Ricardo

    Hello Devin, first of all, great work. My issue is as follows: I am trying to display a category of the portfolios in one page and another category in another page. Is there a way to do this? TY for your time.

  13. AnyDog

    Hi,
    first of all – thanks to great code you put together – however I had one issue with add_theme_support(‘post-thumbnail’, array( ‘portfolio’ ) ) I added to plugin – it overwrites existing support for post thumbs for every other post type.
    So – what I did was add this code (with a bit of a WP forum help):

    function portfolio_post_thumb() {

    $thumbSupportedIn = get_theme_support( ‘post-thumbnails’ );
    $thumbForPorfolio = array(‘portfolio’);
    $postThumbnailTypes = array_merge( $thumbSupportedIn[0], $thumbForPorfolio );
    add_theme_support( ‘post-thumbnails’, $postThumbnailTypes );

    }
    add_action(‘init’,’portfolio_post_thumb’);

    So far, it works for me, so – you might have some use of this .

    Best … :)

      1. AnyDog

        Hi Devlin,
        (my name is Alen, actually … ;) )
        If this suggestion will help you at all, I’m very glad ! :)

  14. Gabriella

    Thank you for the plugin – it’s very lightweight and just what I was looking for. I’m just running into one issue – when I created archive-portfolio.php, it works great for the /portfolio directory listing, but when I view a category archive created under the portfolio plugin, the default archive.php overrides archive-portfolio.php. Is there a way to have archive-portfolio.php be the default for the portfolio category pages?

  15. Sebastián

    Hi, how can i echo the tags in a loop, i’ve tried by using this code:

    but it’s not working, can you help me out please?
    Thanks

  16. Thanks for creating this very useful plug-in. It’s great to be able to have a separate post type.

    Is it possible to change the name of the post type? At the moment, it says “Sermons” but I would like it to say “Talks” instead, especially in the URL, as this is more general and wider-ranging. How would I change this exactly, and what file should I be looking at? Where would I find it? And how many different files would I need to edit?

    Thanks.

  17. Tanja

    Dear Devin,
    is there an easy way to change the label for portfolio category (I would need a german word) and also the way category is displayed?
    Thanks, Tanja

Leave a Reply to Devin Cancel reply