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.
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
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.
This codex article explains how the template hierarchy works: http://codex.wordpress.org/Template_Hierarchy
If you don’t have a single.php you can rename index.php and use it instead.
Thanks for this work. It is good to have clear examples to learn from. Good things will come your way.
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!
It’s a custom taxonomy, so it wouldn’t show up like a regular post category. You can read more about it in the codex: http://codex.wordpress.org/Taxonomies
I’ts working! thanks Devin, for all this.
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.
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?
Either don’t insert your image into the post, or turn of the automatic display of images in the options panel.
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!!
Taxonomy pages will default to archive.php unless you are using a more specific taxonomy template (e.g. portfolio_category.php). See the template hierarchy here: http://codex.wordpress.org/Template_Hierarchy.
In Portfolio Press I also wanted the portfolio taxonomy templates to use the portfolio-archive.php, so I wrote a filter to override the default template hierarchy. See function portfoliopress_template_chooser in: https://github.com/devinsays/portfolio-press/blob/master/functions.php
Thanks Devin :)
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.
I think you code got cut off. Can you paste it into pastebin (or somethign) and link? What is the walker for?
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
You shouldn’t be doing a specific query. You should just use the loop: while ( have_posts() ) : the_post();. Not sure why that wouldn’t be returning the correct items for you.
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.
You can probably just open up the plugin and do a straight find/replace of “portfolio” -> “purchase”. And then, yes, you’d need to rename those templates.
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!
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!
It should work fine out of the box. Perhaps there’s a plugin conflict? Could you disable all your other plugins to see?
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.
Taxonomies automatically get their own archive pages- you shouldn’t need to set up anything special.
How to make portfolio images as links instead of lightbox (a larger image on clicking)
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 … :)
Hi Asirola. Thanks for the bug report, I’ll look into it. Started this issue on GitHub: https://github.com/devinsays/portfolio-post-type/issues/43
Hi Devlin,
(my name is Alen, actually … ;) )
If this suggestion will help you at all, I’m very glad ! :)
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?
Is it a custom taxonomy? You can override the default template using the template_include filter. I am doing it in Portfolio Press for several templates: https://github.com/devinsays/portfolio-press/blob/master/extensions/portfolio-helpers.php
Hi,
How Do I can change the permalink?
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
You can look at what I do in Portfolio Press: https://github.com/devinsays/portfolio-press/blob/master/extensions/template-helpers.php#L45-L46
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.
Hi. There’s instructions in the readme.md: https://github.com/devinsays/portfolio-post-type. Labels are for the text that displays. “Rewrite” is for the URL.
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