고급 사용자 지정 필드의 첫 번째 단만을 어떻게 표시합니까?고급 사용자 지정 필드 내 첫 번째 단락 표시
<?php the_field('lyrics'); ?>
위의 내용은 전체 텍스트를 표시하는 데 사용됩니다.
고급 사용자 지정 필드의 첫 번째 단만을 어떻게 표시합니까?고급 사용자 지정 필드 내 첫 번째 단락 표시
<?php the_field('lyrics'); ?>
위의 내용은 전체 텍스트를 표시하는 데 사용됩니다.
add_filter('wp_trim_excerpt', 'my_custom_excerpt', 10, 2);
function my_custom_excerpt($text, $raw_excerpt) {
if(! $raw_excerpt) {
$content = apply_filters('the_content', get_the_content());
$text = substr($content, 0, strpos($content, '</p>') + 4);
}
return $text;
}
try this code will help you to show first 55 character of your first paragraph.
Grab the first paragraph of each post
초 옵션 :
function custom_field_excerpt() {
global $post;
$text = get_field('news');
if ('' != $text) {
$start = strpos($text, '<p>'); // Locate the first paragraph tag
$end = strpos($text, '</p>', $start); // Locate the first paragraph closing tag
$text = substr($text, $start, $end-$start+4); // Trim off everything after the closing paragraph tag
$text = strip_shortcodes($text);
$text = apply_filters('the_content', $text);
$text = str_replace(']]>', ']]>', $text);
}
return $text;}
세 번째 옵션 : 당신은이 기능을 사용할 수 있습니다
function get_first_paragraph(){
global $post;
$str = wpautop(get_the_content());
$str = substr($str, 0, strpos($str, '</p>') + 4);
$str = strip_tags($str, '<a><strong><em>');
return '<p>' . $str . '</p>';}
을 다음과 루프에서의 사용
<?php echo get_first_paragraph(); ?>
옵션 2의 경우 함수를 만든 후 어떻게 게시물에 표시합니까? –
반환 값으로 $ text를 사용합니다. –
가사 입력란에 무엇을 넣었습니까? –
고급 사용자 정의 필드 wysiwyg를 사용하고 있습니다. 가사의 각 필드에는 1 - 10 개의 단락이 있습니다. –