wordpress - How to add PHP strlen to custom field clauses -


so i'm calling value custom field using standard: $key="mykey"; echo get_post_meta($post->id, key/value, true);

id limit characters displayed in value. i'm not great php, can way around wp, things stump me.

this makes sense me, it's not working:

if (strlen($key="mykey"; echo get_post_meta($post->id, key/value, true)) > 45)     echo substr($key="mykey"; echo get_post_meta($post->id, key/value, true), 0, 45) . ' ...'; else     echo $key="mykey"; echo get_post_meta($post->id, key/value, true); 

any is, always, appreciated! cheers.

indenting code , using variables makes things clearer.

$key  = "mykey"; $val  = get_post_meta($post->id, $key, true);  if ( strlen( $val ) > 45 ) {     echo substr( $val, 0, 45 ); } else {     echo $val; } 

you don't need condition, echo substr( $val, 0, 45 ); same thing


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -