WordPress.org

Ready to get started?Download WordPress

Forums

How to retrieve last word from comment? (3 posts)

  1. delFUEGO
    Member
    Posted 3 years ago #

    Im trying to implement some sort of "Exquisite corpse" (see wikipedia) using wordpress.

    The idea is to have a custom post type (done) for exquisite corpses. The post would be the rules and theme, etc. Then the readers would only see the last word from the last comment approved so they can submit their own comment continuing the story.

    I thought of having 2 post templates for this kind of post. The first would hide the published comments, showing only the last word from the last comment, and the submit box.

    Once its finished, I would switch to the second post template which would show all comments text one after the other, thus creating the story.


    But I need help retrieving the last word from the last approved comment.

    I can figure out the rest.

    Thanks in advance.

  2. Kapil Chugh
    Member
    Posted 3 years ago #

    I thing you can get this from php string function

    http://www.php.net/manual/en/function.strrchr.php

  3. delFUEGO
    Member
    Posted 3 years ago #

    That won't do the trick, if I understood it right, that will retrieve whatever is after the last instance of a given constant. For example, if the constant is a dot, in the following string...

    codex.wordpress.org

    ...it will return "org".

    However, you did point me in the right direction. I searched there for "last word" and came up with this PHP function which I think will do the trick:

    str_word_count

    Maybe I could use that to retrieve all words as an array and somehow discard all but the last item of that array?

    Any thoughts here? Im not that good at PHP, will appreciate the help.

    [EDIT]

    Think I got it...

    $last = end($array);

    Still havent tried all this yet, but in theory it loooks flawless.

    Do I smell a 3-people-in-the-world-could-find-the-useful plugin here? And I'm not even counting me in :D

Topic Closed

This topic has been closed to new replies.

About this Topic