2013-06-10 7 views
-2

게시물 제목에 따라 발췌 내용이 변경되었습니다. 빈칸을 없애기 위해서.글 머리 기호에 따라 wordpress 발췌가 변경

글의 제목에 따라 발췌 부분을 조정 (증가 또는 감소)하고 싶습니다. 예를 들어 (http://www.webdesignerdepot.com/)이 사이트의 발췌 부분은 게시물 제목에 따라 조정됩니다. 게시물 제목이 클 경우 발췌 내용이 줄어들고 그 반대의 경우도 마찬가지입니다. 이 발췌는 게시물 제목의 글자에 따라 조정됩니다.

발췌 부분이 없다고 가정 해 봅니다. 나는 모든 것을 시작부터 원해. 내 질문에 대한 정답 게시물 (http://www.rlmseo.com/blog/changing-excerpt-size-dynamically/를) 찾았지만, 코드가 작동하지 않습니다 -이 업데이트되지, 오래, 그리고 2008 년

내 index.php를 조각에 쓰여진

<div class="mcr-post-area mcr-handheld"> 
    <div class="mcr-item-warp"> 
     <a class="mcr-title2-link" href="<?php the_permalink() ?>"><h2 class="mcr-title2-header"><?php the_title(); ?></h2></a> 
     <div class="mcr-below-title"> 
      <span class="mcr-author"> 
       <i class="icon-user"></i><span>&nbsp; <?php the_author(); ?> </span> 
      </span>    

      <span class="mcr-date"> 
       <i class="icon-calendar-empty"></i>&nbsp; <?php the_time('M j, Y ') ?>  
      </span> 

      <span class="mcr-comment"> 
       <i class="icon-comments"></i> &nbsp; 
       <?php comments_number('no responses', 'one response', '% responses'); ?> 
      </span> 

      <div style="clear:both;"></div> 
     </div> 
    </div><!--mcr-item-warp--> 

    <div class="mcr-post-detial" style="height: auto;"> 
     <div style="margin: 0px; padding: 0px; border: 0px;"> 
      <div class="entry-home"> 
       <?php the_excerpt(strlen(the_title())); ?> 
       <?php the_excerpt(); ?> 
      </div> 
     </div> 
    </div> 

</div> 
+0

여기에서 질문하지 않습니다. 당신은 단순히 사람들에게 당신을 위해 일하도록 요구하고 있습니다. 구현 문제가 발생할 때 직접 뭔가를 구현하고 구체적인 질문을하는 것이 좋습니다. –

+0

@MikeBrant이 –

답변

0
<?php 
// Dynamically resize excerpt according to title length 
$rem_len = ""; //clear variable 
$title_len = strlen(get_the_title()); //get length of title 
if($title_len <= 35){ 
    $rem_len=188; //calc space remaining for excerpt 
}elseif($title_len <= 70){ 
    $rem_len=146; 
}elseif($title_len <= 105){ 
    $rem_len=104; 
}elseif($title_len <= 140){ 
    $rem_len=62; 
} 
$trunc_ex = substr(get_the_excerpt(), 0, $rem_len); //truncate excerpt to fit remaining space 
if(strlen($trunc_ex) < strlen($post->post_excerpt)) $trunc_ex = $trunc_ex . " [...]"; 
echo "<p>" . $trunc_ex . "</p>"; //display excerpt 
?> 
+0

tnx 버디에 대한 모든 스 니펫이 있습니다. 너 락 –

관련 문제