-
AuthorPosts
-
August 12, 2014 at 9:32 am #82844
I’m looking to link the portfolio view (when it shows a category layout) so that when an image or the title is clicked, instead of going to a single portfolio page, it goes to an external URL that is pulled from the project link field.
Any help would be appreciated.
August 12, 2014 at 9:38 am #82847Hi Dave,
Thanks for writing in!
To do so, Add the following codes to the functions.php of your child theme.
This code will make that portfolio item directly link to the “Project Link” instead of the portfolio item page.
add_filter( 'post_type_link', 'x_remap_portfolio_permalink_to_project_link', 10, 4); function x_remap_portfolio_permalink_to_project_link($post_link, $post, $leavename, $sample) { if ('x-portfolio' == $post->post_type) { $custom = get_post_custom($post->id); if (isset($custom['_x_portfolio_project_link']) && $custom['_x_portfolio_project_link'][0]!='') return $custom['_x_portfolio_project_link'][0]; } return $post_link; }
Now when you view the portfolio page, clicking an item will send you directly to the set URL.
Have a nice day, Cheers!
August 12, 2014 at 9:43 am #82852Amazing! Thanks for the quick response!
August 12, 2014 at 9:44 am #82855Glad we were able to help. 🙂 Have a nice day.
August 12, 2014 at 6:23 pm #83352I am wondering: after adding your code to functions.php it works as advertised; however, how do I tell it to open the links in a new page/tab?
August 12, 2014 at 10:25 pm #83440Hi Timothy,
You can edit the URL by going to Dashboard > Portfolio > Select Portfolio Item then scroll down to the Project Link area at the bottom.
Hope that helps!
August 14, 2014 at 9:23 am #84532Oh yeah, great great feature, exactly what I needed.
But you didn’t quite answer Timothy question, which is the same problem I am having…
How can we add a “target=”_blank” to the link?Thanks !
August 14, 2014 at 9:26 am #84535Hey Alex,
You can do it something like this
(function($){ $('.ahref-class-here').attr('target', '_blank'); })(jQuery)
Just change
.ahref-class-here
to the class of your linkCheers
October 29, 2014 at 9:29 am #134411Sorry to revive this topic, but I couldn’t really fix it…
Where should I add this code? Can I add it in the portfolio parent page?
If so, I cannot make it work…Here is how I’m using it:
(function($){ $('.entry-thumb').attr('target', '_blank'); })(jQuery)
Also, if I could apply it only to “.page-id-12826 .x-iso-container-portfolio a” would be better…
Thanks guys
October 29, 2014 at 4:13 pm #134656Hey Alex,
You will need to add the above jQuery code via Appearance > Customize > Custom > Javascript. Let us know how this goes!
October 30, 2014 at 8:35 am #135146Oh… It really was just that haha
Thanks again guys
CheersOctober 30, 2014 at 9:44 am #135213Glad we were able to help. 🙂 Have a nice day.
March 17, 2015 at 9:14 am #229181Hi,
what have to be changed, when just the image and/or headline should goes to an external, but read more to single portfolio page?
With the solution above, also the read more goes to an external url.
Thanks.
March 17, 2015 at 12:56 pm #229345Hi Shakjmaf,
Thanks for writing in!
The provided code changes the link of entire portfolio item, that is, thumbnail, heading, readmore and et cetera. This is the because of the filter hook we’re using to achieve this (http://codex.wordpress.org/Plugin_API/Filter_Reference/post_type_link). In order to achieve your desired results, it requires more in depth changes. It could be possible with custom development, but would fall beyond the scope of support we can offer. You may wish to consult a developer to assist you with this. X is quite extensible with child themes, so there are plenty of possibilities.
Thanks for understanding. Take care!
April 1, 2015 at 12:37 pm #240095Hi,
When you said
Just change .ahref-class-here to the class of your link
I wonder how to set a class to the portfolio link?
Thanks in advance for your answer,
Cheers
-
AuthorPosts