[wp-hackers] basic bilingual plugin: need help with two issues
Silverstein, Jesse
Jesse.Silverstein at xerox.com
Sat Apr 18 15:26:21 GMT 2009
In terms of adding a lang= attribute around post/entry, couldn't this be done with a filter?
add_filter('the_content', 'my_lang_function', 100);
function my_lang_function($the_content) {
$this_lang = my_lookup_lang(get_the_ID());
return "<span lang={$this_lang}">{$the_content}</span>";
}
Or something along those lines.
-Jesse Silverstein
-----Original Message-----
From: wp-hackers-bounces at lists.automattic.com [mailto:wp-hackers-bounces at lists.automattic.com] On Behalf Of Austin Matzko
Sent: Saturday, April 18, 2009 9:07 AM
To: wp-hackers at lists.automattic.com
Subject: Re: [wp-hackers] basic bilingual plugin: need help with two issues
On Sun, Apr 12, 2009 at 3:02 AM, Stephanie Booth <bunnylists at gmail.com> wrote:
> 2. adding lang="" attribute to the post/hentry div
>
> I'd like the plugin to automatically add the correct lang attribute to
> the div containing the post. I've got some code but I'm a bit stuck,
> again:
I'm assuming you want to do this just on singular (i.e. individual
posts or pages) pages; anything else will be almost impossible to do
with output buffering. Instead, you might tell people to put an
action hook at the right place in their templates, such as
do_action('bb_lang_attribute', get_the_ID());
so that you can more robustly do the lookup with a callback function
on that hook.
> function bb_insert_lang_attribute($buffer) {
> $search='/(class="(.)*hentry(.)*")/';
> $replace=\\1 . ' lang="' . bb_get_the_language() . '"';
> return preg_replace($search, $replace, $buffer);
> }
I think you want something like this:
function bb_insert_lang_attribute($buffer) {
$search = '/(class=("|\')[^"\']*hentry[^"\']*\2)/';
$replace = '$1 lang=$2' . bb_get_the_language() . '$2';
return preg_replace($search, $replace, $buffer);
}
> function bb_got_hentry()
> {
> // needs to check for hentry presence
> return false;
Instead of having the hentry logic here, I would put it in the
bb_get_the_language() function: use WP_Query's get_queried_object()
method to get the current object, and do whatever logic check for that
particular post or page at that point.
_______________________________________________
wp-hackers mailing list
wp-hackers at lists.automattic.com
http://lists.automattic.com/mailman/listinfo/wp-hackers
No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 8.0.238 / Virus Database: 270.12.0/2066 - Release Date: 04/18/09 09:55:00
More information about the wp-hackers
mailing list