WordPress.org

Ready to get started?Download WordPress

Forums

Substr() messes up template (6 posts)

  1. marcelvanm
    Member
    Posted 1 year ago #

    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...

  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    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?

  3. marcelvanm
    Member
    Posted 1 year ago #

    It's at this page:

    http://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?

  4. Iamhere
    Member
    Posted 1 year ago #

    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)."...";?>

  5. remita
    Member
    Posted 1 year ago #

    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

  6. heliacal
    Member
    Posted 1 year ago #

    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.]

Topic Closed

This topic has been closed to new replies.

About this Topic