Navigation
This is archived content. Visit our new forum.
  • Author
    Posts
  • #82844

    Dave K
    Participant

    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.

    #82847

    Mrinal
    Member

    Hi 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!

    #82852

    Dave K
    Participant

    Amazing! Thanks for the quick response!

    #82855

    Cousett
    Member

    Glad we were able to help. 🙂 Have a nice day.

    #83352

    Timothy H
    Participant

    I 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?

    #83440

    Paula S
    Member

    Hi 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!

    #84532

    MatthieuH
    Participant

    Oh 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 !

    #84535

    Kosher K
    Member

    Hey 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 link

    Cheers

    #134411

    MatthieuH
    Participant

    Sorry 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

    #134656

    Nabeel A
    Moderator

    Hey Alex,

    You will need to add the above jQuery code via Appearance > Customize > Custom > Javascript. Let us know how this goes!

    #135146

    MatthieuH
    Participant

    Oh… It really was just that haha

    Thanks again guys
    Cheers

    #135213

    Cousett
    Member

    Glad we were able to help. 🙂 Have a nice day.

    #229181

    shakjmaf
    Participant

    Hi,

    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.

    #229345

    Zeshan
    Member

    Hi 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!

    #240095

    rk_skdev
    Participant

    Hi,

    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