-2

Excerpt changing according to post title. For removing the blank space.

I want to adjust (increase or decrease) the excerpt depending on the title of the post. For example (http://www.webdesignerdepot.com/) here in this site the excerpt is adjusted according to the post title. When the post title is large, the excerpt is decreased and vice versa. This excerpt is adjusted according to the letters in the post title.

Suppose there is no excerpt added. I want every thing from start. I found a post (http://www.rlmseo.com/blog/changing-excerpt-size-dynamically/) which is a correct answer to my question, but the code is not working - it is old, not updated, and was written in 2008.

My index.php snippet

<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>
2
  • You are not asking a question here. You are simply asking people to do your work for you. I would suggest you try to implement something yourself and ask specific questions when you run into implementation problems.
    – Mike Brant
    Jun 10, 2013 at 17:41
  • @MikeBrant is there any snippet for this Jun 10, 2013 at 17:44

1 Answer 1

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.