Tagging a piece of text using PHP

I am trying to allow a user (using Wordpress) to insert a jquery slide gallery ( http://www.queness.com/resources/html/slideshow/jquery-slideshow.html ) based on an artificial tag. For example:

[slideshow]
    <img src="url" /><br />
    <img src="url" />
[!slideshow]

Will produce something similar to

<div id="gallery">
     <a href="#"><img src="url" /></a><br />
     <a href="#"><img src="url" /></a><br />
</div>

I think that where I have problems, jquery code requires img to be enclosed with anchor tags. Here, what I have, but thanks to Wordpress, anything above or below the code is not formatted correctly. I used the Wordpress formatting function, but it wraps EVERY line in the 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;

};

SO, . , - , , , , .

+3
3

Wordpress p- ; WP . , , , WP : TinyMCE / wpautop.

+2

, p. , , p .

0

WordPress ?

:

<?php wp_list_pages( $args ); ?> 

<ul> , .

Check the WP dev docs for the subroutine, which is one hierarchy from your subroutine, and I'm sure there will be a value $argfor suppressing tags <p>.

http://codex.wordpress.org/Function_Reference

0
source

Source: https://habr.com/ru/post/1718933/


All Articles