Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I´d like to include an extra two words into an echoed hyperlink. I have no PHP knowledge so far. Could anyone put me in the right direction?

<p class="excerpt"><strong> Bekijk meer van <?php echo get_the_term_list ( $post->ID, 'store' , '' )   ?>

It gives Bekijk meer van storename. I want it to show something like Bekijk meer van extra1 storename extra 2.

share|improve this question
1  
<p class="excerpt"><strong> Bekijk meer van extra1 <?php echo get_the_term_list ( $post->ID, 'store' , '' ) ?> extra 2 –  revo Mar 22 '13 at 10:29
add comment

1 Answer

Never just print the result of get_the_term_list() without additional checks. It might return an instance of WP_Error which is an object, not a string.

Save the result of get_the_term_list() in a variable and print the terms only if there are terms and not an error:

<?php
$stores = get_the_term_list( $post->ID, 'store', '', ', ' );

// We got something back, and it is not an error.
if ( ! empty( $stores ) and ! is_wp_error( $stores ) )
{
    echo "<p class='excerpt'>
        <strong>Bekijk meer van extra1 $stores extra2</strong>
    </p>";
}
?>
share|improve this answer
    
'Save the result of get_the_term_list() in a variable and print the terms only if there are terms ...' is not related to question and the rest is exactly what I commented above. –  revo Mar 22 '13 at 10:48
3  
@revo Whenever possible we use a question to show how to do it better than the asker had it planned. And in its current form there is nothing WordPress specific in the question; I tried to show how it could be a WordPress issue (is_wp_error()). And a comment is not an answer. –  toscho Mar 22 '13 at 10:51
    
poor question doesn't need an answer except for receiving votes. That's the exact manner u did on my better than the asker had it planned answer on the other question. –  revo Mar 22 '13 at 11:14
1  
@revo Agreed, it is not a good question. But the opportunity to point at the error that should not be printed is useful. No idea what other answer you are talking about. If you think a moderator did something wrong raise the issue on WordPress Development Meta or flag it. –  toscho Mar 22 '13 at 11:19
    
thanks for helping me. I cannot seem to figure out on how to implement it, as I have no PHP knowledge whatsoever. Could you please tell me what to replace for what? –  Ramon v Mar 22 '13 at 15:52
show 8 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.