WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to remove the HTML of the post in the homepage preview (11 posts)

  1. utnalove
    Member
    Posted 2 years ago #

    Hello, if I write a post like this:

    ================
    hello, this is a test post. This is to show you how it looks like in the homepage, in the categories pages, in the tag pages and in the archives. With this theme I have to pay attention when I add whatever kind of html tags to the text, especially if they are at the beginning of the posts.
    ================

    In the homepage it appears like this:
    hello, this is a test post. This is to show you how it looks like in the homepage, in the categories pages, in the tag pages and in the archives. With this theme I have to pay attention when I add <strong>whatever kind Read More

    If the read more cuts a <b> tag, a <i>, <strong>, <h1>, <h2>, <img>, <a> etc, the tag does not get closed.

    For example, if the latest words before the "Read More" have a "a href", then ALSO the "Read More" button, will link to that href, instead than to the post article.

    This is the PHP code in question:
    http://pastebin.com/5gVCKSLL

    I have no idea how to resolve this. Did you get what I mean?

  2. s_ha_dum
    Member
    Posted 2 years ago #

    Those content functions don't make any effort to avoid markup mangling. Try adding $content = force_balance_tags($content); to those content functions. You will have to change this:

    $content = implode(" ",$content).'...<a href="'. get_permalink($post->ID) . '">'.__('Read full post','language') .'</a>';

    to this:

    $content = implode(" ",$content);
    $content = force_balance_tags($content);
    $content .= '...<a href="'. get_permalink($post->ID) . '">'.__('Read full post','language') .'</a>';

    See how that works out.

  3. utnalove
    Member
    Posted 2 years ago #

    Hi, it didn't resolve the problem. But it added new errors.
    I've turned back to the original code in order to avoid php errors.

    Please take a look here. In this page you can see very well the error:
    - In the "Atlantic" post, you can see that there is Italics text. Then also the "read more" button becomes italics.

    AND

    Also the below posts become all in Italics :(

    Below in the "detoxdesign" post, you can see that the test is bold, then the </b> tag doesn't get closed and the next posts are both bold and italics :(

    P.s. the code you gave doesn't resolve the issue. In one post it gives me the following error: http://img51.imageshack.us/img51/5529/errorgh.png

  4. s_ha_dum
    Member
    Posted 2 years ago #

    hmmm... I am not sure why my code would produce those errors, unless your content is so scrambled that the force_balance_tags(...) function bogs down. And you code is kind of weird. You have tags like <h2/> and <p/> scattered through the source. I am pretty sure those are not correct.

    Parsing markup well is tricky. I'd hoped the WordPress function would sort it out.

    The problem is that those functions break the post content on spaces-- that is the explode(...) part. If those spaces are inside a tag, so be it. It could even break inside a class or other attribute attribute. I have fought with this more than once.

    Your other option is to remove all of the tags. You could try usingwp_strip_all_tags(...)

  5. utnalove
    Member
    Posted 2 years ago #

    I don't know either why your code renders errors on that post. This is the HTML of that post. Everything seems to be alright. See here: http://img705.imageshack.us/img705/817/postov.png

    By the way it looks like that the errors with your code appear on that post only (maybe also some other, there are 40+ pages). But most of them are without errors.

    If we can make the PHP to close those tags well that would be great. Otherwise also the wp_strip_all_tags would be fine. How can I use that? Should I change the php code?

    P.s. I do not see tags such as <h2/> and<p/>. They all have the slash in the right place </h2> </p>

  6. s_ha_dum
    Member
    Posted 2 years ago #

    If we can make the PHP to close those tags well that would be great.

    I know. That is certainly the best option.

    By the way it looks like that the errors with your code appear on that post only (maybe also some other, there are 40+ pages).

    It has got to be when the content is broken at a particularly strange place. You probably need to insulate the content string so that it never gets broken inside a tag. force_balance_tags(...) should be able to clean up the mess.

    You can try using something like what is found here: http://codex.wordpress.org/Function_Reference/get_the_excerpt

  7. utnalove
    Member
    Posted 2 years ago #

    I really don't know what to do. I wrote to the theme developer asking for help.

  8. utnalove
    Member
    Posted 2 years ago #

    I have an update. Those php errors where just an error that for some reason the server could not connect temporarily to facebook to get the right number of comments (WP + FB). Now with your code there are no errors.

    However your code still doesn't add the closing markup tags. I have right now your code on. I didn't remove it yet. I hope you are online now. I will leave your code on another few hours, hoping you can check back the blog with your code in place.

    Just to update. The code now looks like this http://pastebin.com/8vRavbRt

    And in the header it is still like this http://pastebin.com/d7GzFsHF

  9. utnalove
    Member
    Posted 2 years ago #

    WOW!!! I think I found it out!!!! Maybe it is resolved, I have to test it out...

    As you can see in the code I have the following code:
    $content = implode(" ",$content).'...<a href="'. get_permalink($post->ID) . '">'.__('Read full post','language') .'</a>';

    In two places. In the function content($limit) and in the function contentnoimg($limit). I added it ALSO to the contentnoimg. And it looks like it is working.

    Now I am wondering whether I have to keep your code in both functions or leave it in the contentnoimg only...

    What do you think?

  10. s_ha_dum
    Member
    Posted 2 years ago #

    It looks to me like you would need to modify both functions.

  11. utnalove
    Member
    Posted 2 years ago #

    Thanks much

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags