• I’m trying to limit the amount of characters that will be displayed for the product description so I replaced this
    <?php echo wpsc_the_product_description(); ?>

    with this
    <?php echo substr(wpsc_the_product_description(),0,250); ?>

    on one of my pages and now something happens that messes it up my template.

    Can someone give me a pointer to what I need to do (or must not do) to fix this?

    This is the first time I’m trying to use substr() so perhaps it’s something simple…

Viewing 5 replies - 1 through 5 (of 5 total)
  • if the ‘wpsc_the_product_description()’ contains any html tags, ‘substr’ is likely to break them – which will lead to display problems.

    can you post links to examples of the problem?

    Thread Starter marcelvanm

    (@marcelvanm)

    It’s at this page:

    https://vmtweewielers.nl/2012/products-page/alledamesfietsen/

    As you can see the page isn’t how it should be looking.

    Is there a way that substr() will leave the html intact?

    Try this:

    Put this in function.php

    function string_limit_words($string, $word_limit)
    {
    $words = explode(‘ ‘, $string, ($word_limit + 1));
    if(count($words) > $word_limit)
    array_pop($words);
    return implode(‘ ‘, $words);
    }

    <?php // put this where you want to echo it out
    $excerpt = wpsc_the_product_description(); echo string_limit_words($excerpt,50).”…”;?>

    Hi,

    Iam using the wpsc_the_product_description(); in one of my theme page..

    and in function page I use the function
    function wpsc_the_product_description() {
    $content = get_the_content( __( ‘View More …’, ‘wpsc’ ) );
    return do_shortcode( wpautop( $content,1 ) );
    }

    But it not working with <!–more–> tag.
    Its displaying all the content.
    Any idea?

    Thanks
    Remita

    There is an anouther decision of the problem whith
    <?php echo substr(wpsc_the_product_description(),0,250); ?>

    It is<?php $excerpt=strip_tags(wpsc_the_product_description()); echo substr($excerpt,0,250)."..."; ?> And no mud in your template.

    [Moderator Note: Please post code or markup snippets between backticks or use the code button. As it stands, your code may now have been permanently damaged/corrupted by the forum’s parser.]

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Substr() messes up template’ is closed to new replies.