I’m trying to allow a user (using WordPress) to insert a jquery slideshow gallery (http://www.queness.com/resources/html/slideshow/jquery-slideshow.html) based on a faux tag. For example:
[slideshow]
<img src="url" /><br />
<img src="url" />
[!slideshow]
Would produce something similar to
<div id="gallery">
<a href="#"><img src="url" /></a><br />
<a href="#"><img src="url" /></a><br />
</div>
I think where I’m having problems is the jquery code requires the img to be enclosed with anchor tags. Here’s what I have, but thanks to WordPress, anything above or below the code isn’t formatted correctly. I’ve used the WordPress formatting function, but it wraps EVERY line in a paragraph tag, so it just breaks everything.
function make_slideshow($string) {
$patterns[0] = '/([[slideshow]])/';
$patterns[1] = '/([[!slideshow]])/';
$replacements[0] = '<div id="gallery">';
$replacements[1] = '<div class="caption"><div class="content"></div></div></div>';
$replace = preg_replace($patterns, $replacements, $string);
$new_line = explode("n", $replace);
foreach($new_line as $key => $value) {
if($value == "" || $value == " " || is_null($value)) {
unset($new_line[$key]);
}
}
$sorted_lines = array_values($new_line);
foreach($sorted_lines as $key => $value){
if( (stristr($value, 'href') === FALSE) && (stristr($value, 'img') !== FALSE) ){
$sorted_lines[$key] = '<a href="#">' . $value . '</a>';
}
if( (stristr($value, 'show') === FALSE) && ($key === 1) ){
$value = explode(" ", $value);
$value[0] .= ' class="show"';
$sorted_lines[$key] = implode(" ", $value);
}
}
return $sorted_lines;
};
Normally I find all my other answers on SO, so this is only my first question. I don’t know if it’s way too big of a problem for someone else to try to help me out with, but I am stuck so I figured I’d give it a shot.
WordPress adds p tags automatically in the editor; you need to stop WP from doing that. In my experience, you either remove all line breaks in the editor – scrunch the code up – or use a few plugins, to stop WP from adding the formatting: TinyMCE Advanced and/or Disable wpautop.
There’s nothing in that code that adds a p tag. If that’s the problem, you need to find the real code that adds p as a wrapper.
What WordPress function is calling your routine?
I had a similar problem with:
Was adding
<ul>
links to everything I wanted to surpress..Check the WP dev docs for the routine that is up one hierarchy from your routine and I bet there will be an
$arg
value to suppress<p>
tags.http://codex.wordpress.org/Function_Reference