2014-05-21 98 views
0

我有一個自定義content-searchresults.php頁面。然而,由於某種原因,它沒有顯示摘錄,但其他修改我使這個被拉過所以它使用這個模板。Wordpress自定義搜索結果頁面未顯示摘錄

以下是我的代碼。

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> 


     <?php if (has_post_thumbnail() && ! post_password_required() && !is_single()) : ?> 


      <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" > 
       <?php the_post_thumbnail('full', array('class' => 'img-responsive')); ?> 
      </a> 


     <?php endif; ?> 

     <div class="clearfix"> 
      <header class="entry-header "> 
       <?php if (in_array('category', get_object_taxonomies(get_post_type())) && CrippsTheme_categorized_blog()) : ?> 
       <div class="entry-meta"> 
        <span class="cat-links"><?php echo get_the_category_list(_x(', ', 'Used between list items, there is a space after the comma.', 'CrippsTheme')); ?></span> 
       </div> 
       <?php 
        endif; 

        if (is_single()) : 
         the_title('<h1 class="entry-title">', '</h1>'); 
        else : 
         the_title('<h1 class="entry-title"><a href="' . esc_url(get_permalink()) . '" rel="bookmark">', '</a></h1>'); 
        endif; 
       ?> 

      </header><!-- .entry-header --> 
     </div> 


    <div class="entry-summary clearfix"> 
     <?php the_excerpt(); ?> 
    </div><!-- .entry-summary --> 
    <div class="clearfix"> 
    <a class="read-more" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" > 
     Read more 
    </a> 
    </div> 

回答

0

它不是認爲它不是顯示它摘錄的是,我曾與在主副本先進的自定義字段。要顯示一個先進的自定義字段摘錄我用了下面。

添加到functions.php中

function custom_field_excerpt() { 
global $post; 
$text = get_field('main_copy'); 
if ('' != $text) { 
    $text = strip_shortcodes($text); 
    $text = apply_filters('the_content', $text); 
    $text = str_replace(']]>', ']]>', $text); 
    $excerpt_length = 45; // 45 words 
    $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]'); 
    $text = wp_trim_words($text, $excerpt_length, $excerpt_more); 
} 
return apply_filters('the_excerpt', $text); 
} 

然後添加以下到您想摘錄顯示:

<?php echo custom_field_excerpt(); ?> 
相關問題