treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Updated content notifications?

  • Ok, on my WordPress site I use custom fields a lot. I am using a plugin called Magic Fields 2 which basically just lets you create custom admin panels in the post/page write sections using custom fields. I have been looking for a way to show things that are new or updated using css. Like a little notification bubble, or color border or something. Anything I can do to make new items since a user's last visit stand out so they can readily see what is new.

    I have tried a lot of things and can't seem to find an existing plugin or documentation in the wordpress codex. There are plugins that will email you when a post or page is updated, but they don't notify you if any custom field is added or changed or updated, only the actual page or post content.

    Hope that makes sense...would appreciate any help in figuring this out. Would be great to have something that not only shows what is new or updated, but would allow for such items to be marked as read. If it helps, the pages where I am doing this is only accessible by logged in users.

    Thanks in advance!!

    ~ Kahil
  • Some kind of code that would get the custom field's timestamp and then if that custom field was added/edited/modified on today's date, it would output the word "today" rather than the date format would be helpful. I could then do some custom css for anything with a class of "today".

    been googling all day trying to find a workable solution with no luck...
  • write a JavaScript function to post the page ID and the time the page was last updated to a PHP file which will compare the time posted and the current time for the page in question and if there is a different echo back the result (a Boolean value or a number of changes), back in the JavaScript file use the returned value to determine how to notify the user

    to run this function every 30 seconds

    setInterval(yourFunctionName, 3000);

    *NB the timestamp on the page should be done by PHP instead of JavaScript because the client's time might be different to your server
  • Ummm... Ok... I don't know how to do that...sorry, just learning some things. I'm pretty good at understanding javascript when analyzing completed script and then figuring out what does what, but I don't know how to do so from scratch.

    I don't need a script that checks the page itself, WordPress already has a php code that does that. I'm looking for something more specific that pulls the timestamp for different custom fields on the page.

    I'm trying to keep it real simple here. Just looking for a way to pull the timestamp for custom fields. If the custom field was added, edited or modified on today's date, then instead of outputting date format it would output and display as "today". That way can I use that outputted text as a css class. If the div has the class of "today" then it would display something a little different to signify that it is new.
  • if your custom fields have IDs then you can select them with either getElementById in JavaScript or $('#ID') in jQuery, and thats just two of the many ways, best thing to do is head over to jsfiddle.net, simulate some output and console.log(); the hell out of everything until you get it right

    As for converting the time to "today"
    Get the timestamp of the start of the day, the current timestamp and the post timestamp

    If the post timestamp is between the other two then you return Today as so on

    this would be best achieved with UNIX time
    <?php time(); ?>

    Let me know if you would like links to some documentation and come back anytime you need nudging along :)
  • well... as with javascript, I do not know jquery either.

    another thing, with WordPress, custom fields don't have IDs attached to them. That isn't how it works. for this to work i'm probably going to have to find a way to pull the info from the database the custom fields are stored in. honestly if it were just as simple as using an ID and the time php code I could have and would have done that...tried that too.
  • Take a look at the Wordpress loop PHP file
    This contains the function to output the posts, you will be able to add your own IDs to the fields in here

    The name and location of this can change based on the theme you are using so Google will be your friend here

    Chris has some videos on this site which will help
    here's one of them
    http://css-tricks.com/video-screencasts/91-the-wordpress-loop/