WordPress.org

Ready to get started?Download WordPress

Forums

Problem with columns and custom fields/truncate function (5 posts)

  1. cybervampira
    Member
    Posted 2 years ago #

    I've set up twenty eleven as a child theme and created a custom page with advanced custom fields. I created a page with 2 columns and everything works great until I used truncated text.

    I use this code in my functions.php and it's working as supposed to be:

    function trunc($phrase, $max_words)
    {
    $phrase_array = explode(' ',$phrase);
    if(count($phrase_array) > $max_words && $max_words > 0)
    $phrase = implode(' ',array_slice($phrase_array, 0, $max_words)).'...'
    return $phrase;
    }

    However, I'm experiencing a problem with my page when using this function in columns. As long as I am using the get_field alone without trunc, the columns look OK but as soon as I'm using trunc, I have a problem with the first column, second row moving over to the second column. You can check it here: http://tierhilfe-spanien.org/zuhause-gesucht/huendinnen/

    Here's the code I'm using in my template file (sorry for the spaghetti code but I'm new to PHP and WP):

    http://pastebin.com/0dRdfB1t

  2. vtxyzzy
    Member
    Posted 2 years ago #

    The problem is likely due to 'broken' HTML caused by simply counting words. That probably ends up having some opening tags with no corresponding closing tag.

    Here is an article with code for a custom excerpt function which will handle many of the problems:

    http://wordpress.mcdspot.com/2012/01/21/custom-excerpt-to-handle-broken-html/

  3. cybervampira
    Member
    Posted 2 years ago #

    Unfortunately, this didn't solve my problem. Instead I'm having two problems now: Same as before and foreign characters are not shown correctly (i.e. "ö" instead of "ö"). Any other idea what the problem could be?

  4. cybervampira
    Member
    Posted 2 years ago #

    Ha! I was able to fix the issue about columns. But not about the foreign characters now showing correctly. Any ideas?

  5. vtxyzzy
    Member
    Posted 2 years ago #

    It sounds like the DOMDocument is changing the character encoding. There may be a parameter to DOMDocument() for that, but I don't know.

Topic Closed

This topic has been closed to new replies.

About this Topic