For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > March 2008 > PHP strokes WP









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author PHP strokes WP
Mateusz Pozar

2008-03-10, 8:01 am

Good evening all.

I'm looking to implement a function into a Wordpress blog, and I'm quite
certain that I could pull it off using PHP. I'd hope someone with actual
knowledge of the language might tell me if I'm on the right track.

I have a thesaurus of words in a special category on the blog. The
category doesn't appear anywhere other than in the category listing.
Each word is listed in it's own post, with the title of each post as the
name of what is defined, and the post body is the definition.

Like so:

Post title - Red
Post body - The colour of my bleeding eyes.


Let's say that I have a post on the front page that looks like this:

Violets are blue, roses are red, if I don't get this to work, I'll kill
myself dead.


I need a script that would look over the text on any page where it is
included, and see if it matches any of the titles in the 'thesaurus'
category, and in that case print the title and post of that word into a
div (which I then would style into it's own pretty box in the right margin).

As in the above example (broken up for legibility):

Violets are blue, roses are red
<div class="definition">
<span class="def_title">
Red
</span>
<span class="def_body">
The colour of my bleeding eyes.
</span>
</div>
, if I don't get this to work, I'll kill myself dead.

It should only do this once for every word on any given page, so that
the sentence

"Herrings can be really red, as red as red can get"

Would only trigger the 'red' definition once.

The way I imagine that I could go about this is to get all post titles
of a category, put them into an array, and then put the script inside
the Wordpress loop and let it search the resulting page for matches to
the array, and then print the corresponding DIV.

This method of presenting the definition is not an elegant way to go
about it - any feed reader app not allowing the inline style I'm
supplying will break down sobbing - so ideally the DIVs should be
printed outside of the blog posts. Oh, and it needs to support
non-English characters (Swedish, in this case).

Let me know if I'm going about this the wrong way. I know this falls
between Wordpress hacking and PHP proper, but it requires more PHP than
I've been able to gleam from the WP support pages. Having spent more
than 30 hours adapting existing plugins, PHP hacks and Javascript, I
need to start over and would appreciate any pointers.


Cheers
Mateusz

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com