0

I'm developing a gallery plugin that shows featured image as album cover. But I need to show some text info in this album cover. So I got the image title to be the name, its working ok. But for the description I need to have 2 lines (one for the info and one for the phone), So I thought that I could use the caption with a line break [return] or even using the br tag, but both does not work (came empty). It only works with a single line text. See my code below, I must be doing something wrong. Any help will be appreciated.

 if( $query->have_posts() ) { $response = '<div id="galery">'; while( $query->have_posts() ) { $query->the_post(); if( has_post_thumbnail( get_the_ID() ) ) { $response .= '<div class="image">'; $response .= '<a href="' . get_permalink( get_the_ID() ) . '" title="' . esc_attr( get_the_title( get_the_ID() ) ) . '">'; $photo = get_the_post_thumbnail( get_the_ID() ); preg_match('/alt="(.*)"/',$photo,$matches); $response .= $photo.'</a>'; $response .= '<div class="tarja"><span class="name">'.esc_attr( get_the_title( get_the_ID() ) ).'</span><br/>'; $response .= '<span class="info-phone">'.$matches[1].'</span></div></div>'; } } $response .= '</div>'; } wp_reset_query(); return $response; 

}

2
  • After saving the content, do you still see the line break in the caption field? My guess is that the caption field gets all tags stripped. Commented Jan 18, 2017 at 18:39
  • Yeah, if I go to caption the text are ok and with linebreak. Commented Jan 18, 2017 at 18:42

1 Answer 1

0

Use two different custom fields rather than using caption. You can manage custom fields better than caption because caption doesn't support html tags. You can use Advanced custom field (ACF) plugin for this purpose it's super easy to use and manage fields.

3
  • Great. I've already created a custom field and added it to attachments, now it is apearing in the image properties, next to the other fields. But when I try to get the info using the code below inside the looping above it comes empty. I'm doing that wrongly? $cel = get_field('cel'); $response .= '<span class="cel">' .$cel. '</span></div></div>'; Commented Jan 19, 2017 at 2:45
  • If you are using ACF fields then u need to call them in this way. $cel = the_field('cel'); and if you want to echo it out of the loop then you can use id like this `$cel = the_field('cel' , 'page_id' ); Commented Jan 19, 2017 at 5:53
  • I've got the post id with $post_thumbnail_id = get_post_thumbnail_id( get_the_ID() ); so I got the cel value with $cel = the_field('cel'); and finally I've inserted that into span with $resposta .= '<br/><span class="cel">' .get_post_meta(get_post_thumbnail_id(), 'cel', true). '</span>';. Thanks a lot . Commented Jan 23, 2017 at 4:02

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.