I think I don't really understand your question but I'll try to explain what I know anyway

.
When building a simple chat system you have to go through these steps:
- On page load check the database for the latest messages and players online and display them.
- Every X seconds you do an ajax call to run a php script and check the database for new messages and check users online (or you could check users online every X minutes or so, to save some resources).
- When the players sends a chat message you do an ajax call to a php script to save the message to the database + update the chat
That's it (at least I think that's it

). You just have to make sure you implement your "special" chat features in the correct place.
For example: if a user sends a private message "/w username blabla" you check the first X characters of the string and if it matches "/w" (or another command like "/g or whatever) you check the username and save it in the correct place in the database. When you display your chat you make sure to check regular, private and guild messages.
You see what I mean? Or do I need to be more specific?