Hallo!
Ich benutze folgendes Plugin, dammit Hyperlinks zu Bildern automatisch ein rel="lightbox[ID]" hinzugefügt wird.
Hier könnt ihr den Code des Plugins sehen (es ist nur eine Datei).
<?php
/*
Plugin Name: Add Lightbox
Plugin URI: http://mdkart.fr/blog/2007/06/14/plugin-add-lightbox-pour-wordpress/
Description: This plugin automatically add the rel="lightbox[ID_OF_THE_POST]" to images linked in a post. ID_OF_THE_POST is unique per post so all images per post are grouped in one lightbox set. Doesn't add the the files required for lightbox!
Author: Mdkart
Author URI: http://mdkart.fr
Version: 0.1
Put in /wp-content/plugins/ of your Wordpress installation
Inpsired by this thread : http://wordpress.org/support/topic/106529
*/
add_filter('the_content', 'addlightboxrel_replace');
function addlightboxrel_replace ($content)
{ global $post;
$pattern = "/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";
$replacement = '<a$1href=$2$3.$4$5 rel="lightbox[%LIGHTID%]"$6>';
$content = preg_replace($pattern, $replacement, $content);
$content = str_replace("%LIGHTID%", $post->ID, $content);
return $content;
}
?>
Alles anzeigen
Nun meine Frage (ich habe schon in mehreren Foren gefragt, aber mir konnte niemand helfen).
Wie kann ich verhindern, dass das rel="lightbox[ID]" einem Bildlink hinzugefügt wird, wenn er das Ziel target="_blank" hat?
Zur Erklärung:
<a href="http://www.dom%c3%a4ne.net/bild.jpg" title="Bild"/> -> <a href="http://www.dom%c3%a4ne.net/bild.jpg" rel="lightbox[19]" title="Bild"/>
<a href="http://www.dom%c3%a4ne.net/bild.jpg" title="Bild" target="_blank"/> -> soll gleich bleiben (nicht ändern!)
Es muss doch irgendwie möglich sein, dem Sichmuster $pattern eine Art nicht target="_blank" hinzuzufügen, oder?