Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #1000071

    I am using this code to show show tags through a shortcode on my portfolio items, to help with SEO:

    function show_portfolio_tags_func() {
    	global $post;
    	$the_tags = get_the_tags( $post->ID , 'portfolio_entries');
    	$output = '';
    	foreach($the_tags as $tag) {
    		$taglink = get_tag_link($tag->tag_id);
    		$output .= '<span class="portfolio_tag"><a href='.$taglink.'>'.$tag->name.' </a></span>';
    	}
        return $output;
    }
    add_shortcode('portfolio_tags', 'show_portfolio_tags_func');

    It’s working fine, but the tags are very close together – see https://imgur.com/a/N6Rsbmi
    and the links that are attached to them do not lead to a list/gallery of items for that tag, but back to the same page.
    Can you help me with this?
    thanks very much
    Nancy

    #1000295

    Hey Munford,

    Here is the code you can put in Enfold > General Styling > Quick Css,  if it does not work, put into themes/enfold/css/custom.css

    
    .portfolio_tag {
        margin-right: 10px;
    }
    

    If you need further assistance please let us know.

    Best regards,
    Victoria

    #1000361

    Hi VIctorica
    thanks for the help! Is it possible to put a “/” between the tags as well?

    Can you also look at the 2nd issue – the links that are attached to the tags do not lead to a list/gallery of items for that tag, but back to the same page. I don’t think that’s how it’s supposed to work, right? Is there something wrong in the function code above?

    Best
    Nancy

    • This reply was modified 6 years, 3 months ago by Munford.
    #1001106

    Hi Nancy,

    Please try the code like this:

    
    function show_portfolio_tags_func() {
    	global $post;
    	$the_tags = get_the_tags( $post->ID , 'portfolio_entries');
    	$output = '';
    	foreach($the_tags as $tag) {
    		$taglink = get_tag_link($tag->tag_id);
    		$output .= '<span class="portfolio_tag"><a href='.$taglink.'>'.$tag->name.'/</a></span>';
    	}
        rtrim($output, '/');
        return $output;
    }
    add_shortcode('portfolio_tags', 'show_portfolio_tags_func');
    

    If you need further assistance please let us know.
    Best regards,
    Victoria

    #1001108

    Hi victoria,

    thanks- but that code is giving me this error on this line:
    $the_tags = get_the_tags( $post->ID , ‘portfolio_entries’);
    the & is in the code for the > ($the_tags = get_the_tags( $post-&GT;ID , ‘portfolio_entries’);)

    Your PHP code changes were rolled back due to an error on line 109 of file wp-content/themes/enfold-child/functions.php. Please fix and try saving again.

    syntax error, unexpected ‘&’

    is there something wrong in the code?
    thanks for your help
    Nancy

    • This reply was modified 6 years, 3 months ago by Munford.
    #1001253

    Hi Nancy,

    Try it like this:

    
    
    function show_portfolio_tags_func() {
    	global $post;
    	$the_tags = get_the_tags( $post->ID , 'portfolio_entries');
    	$output = '';
    	foreach($the_tags as $tag) {
    		$taglink = get_tag_link($tag->tag_id);
    		$output .= '<span class="portfolio_tag"><a href='.$taglink.'>'.$tag->name.'\/</a></span>';
    	}
        rtrim($output, '/');
        return $output;
    }
    add_shortcode('portfolio_tags', 'show_portfolio_tags_func');
    

    Best regards,
    Victoria

    #1001270

    Hi again

    That looks better but the links are still not working correctly – they are all leading back to the same page instead of to the tag categories.
    Can you please check it?
    Thanks for your help
    Nancy

    • This reply was modified 6 years, 3 months ago by Munford.
    #1001595

    Hey Nancy!

    You need to check what you’re getting in the $taglink variable here.

    Cheers!
    Victoria

    #1001632

    I don’t write code and don’t understand what that means. All the tags are link back to the parent page right now. They should lead to the different tag categories.

    I looked at another thread https://kriesi.at/support/topic/tags-in-portfolio-dont-link-to-corresponding-tag-archive/#post-840434 which gave this code instead of the one you gave me for the portfolio tags for someone having the same problem.

    function avs_show_portfolio_tags_func() {
    	global $post;
    	$the_tags = get_the_tags( $post->ID );
    	$output = '';
    	foreach($the_tags as $tag) {
    		$taglink = get_tag_link($tag->term_id);
    		$output .= '<span class="portfolio_tag"><a href='.$taglink.'>'.$tag->name.' </a></span>';
    	}
        return $output;
    }
    add_shortcode('portfolio_tags', 'avs_show_portfolio_tags_func');

    It seems to work – as it links to the portfolio tags now – but there are no items coming up on those pages. Can you check this please on the page below?
    thanks
    Nancy

    • This reply was modified 6 years, 3 months ago by Munford.
    #1001825
    #1001851

    yes you did, thanks so much! you can close this thread

    #1001857

    Hi,

    Great, glad it works now :)

    Best regards,
    Dude

Viewing 12 posts - 1 through 12 (of 12 total)
  • The topic ‘portfolio tags styling, links’ is closed to new replies.