php - Foundation Magellan auto generate -


i'd auto generate magellan on subpages h3 tags. purpose tried jameswlane script (https://gist.github.com/jameswlane/f1eabeedf430ef67318d), , changed h2 tags h3. seems dont aunderstand code well.

i thought need paste code in header.php file wordpress theme , automatically sweep dom content h3 tags, didn't.

nothing shows up, empty div.

used followinf line init:

<?php $tag = 'h3'; $html = get_the_content(); $items = gettextbetweentags( $tag, $html ); ?> 

can ask advise in matter?

<?php  function gettextbetweentags($tag, $html, $strict=0) { $dom = new domdocument; if($strict==1) {     $dom->loadxml($html); } else {     $dom->loadhtml($html); } $dom->preservewhitespace = false; $content = $dom->getelementsbytagname($tag); $out = array(); foreach ($content $item) {     $out[] = $item->nodevalue; } return $out; }  function create_slug($string){ $slug=preg_replace('/[^a-za-z0-9-]+/', '-', $string); return $slug; }  function create_magellan($items){ $output .= '<div data-magellan-expedition="fixed">' . php_eol; $output .= '<dl class="sub-nav">' . php_eol; foreach( $items $item ) {     $output .= '<dd data-magellan-arrival="' . create_slug( $item ) . '"><a href="#' . create_slug( $item ) . '">' . $item . '</a></dd>'; } $output .= '</dl>' . php_eol; $output .= '</div>' . php_eol; add_filter('the_content', 'my_formatter', 99); echo $output; }  function my_formatter($content) { $new_content = ''; $tag = 'h3'; $pattern_full = '{(<' . $tag . '>.*?</' . $tag . '>)}is'; $pattern_contents = '{<' . $tag . '>(.*?)</' . $tag . '>}is'; $pieces = preg_split($pattern_full, $content, -1, preg_split_delim_capture);  foreach ($pieces $piece) {     if (preg_match($pattern_contents, $piece, $matches)) {         $test = $matches[1];         $new_content .= '<a name="'.create_slug($test).'"></a>'.php_eol.'<'.$tag.' data-magellan-destination="'.create_slug($test).'">'.$test.'</'.$tag.'>'.php_eol;     } else {         $new_content .= wptexturize(wpautop($piece));     } } return $new_content; }  ?> 

edit

something worked , returned error:

warning: domdocument::loadhtml(): empty string supplied input in /www/ilee_www/www/2.goldbaltic/dev.goldbaltic.pl/wp-content/themes/dermiclab_fs/partials/2.nav/mainnav.php on line 47 

the line number 47 in file

$dom->loadhtml($html); 

from

 function gettextbetweentags($tag, $html, $strict=0) {     $dom = new domdocument;     if($strict==1) {         $dom->loadxml($html);     } else {         $dom->loadhtml($html);     }     $dom->preservewhitespace = false;     $content = $dom->getelementsbytagname($tag);     $out = array();     foreach ($content $item) {         $out[] = $item->nodevalue;     }     return $out; } 


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -