-
-
Save wordpressvn/a9498d7fedb7289882d7a2c27adf4853 to your computer and use it in GitHub Desktop.
Revisions
-
vielhuber revised this gist
Mar 27, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,7 +24,7 @@ function wp_split_more($content, $type, $more_html = null) // remove gutenberg tags foreach (['before', 'after'] as $g1__value) { foreach (['/', ''] as $g2__value) { foreach (['wp:paragraph', 'wp:more', 'wp:html', 'wp:tadv/classic-paragraph'] as $g3__value) { $return[$g1__value] = str_replace( '<!-- ' . $g2__value . '' . $g3__value . ' -->', '', -
vielhuber revised this gist
May 12, 2020 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -63,6 +63,9 @@ function wp_split_more($content, $type, $more_html = null) // add opening / closing p-tags foreach ($return as $return__key => $return__value) { if ($return[$return__key] == '') { continue; } $return[$return__key] = (mb_strpos($return[$return__key], '<p') !== 0 ? '<p>' : '') . $return[$return__key] . -
vielhuber revised this gist
May 12, 2020 . 1 changed file with 5 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -80,9 +80,8 @@ function wp_split_more($content, $type, $more_html = null) echo wp_split_more(get_post_field('post_content', get_the_ID()), 'before', '<a href="'.get_permalink(get_the_ID()).'" class="more">>>></a>'); echo '</div>'; if( wp_split_more(get_post_field('post_content', get_the_ID()), 'after') !== null && wp_split_more(get_post_field('post_content', get_the_ID()), 'after') != "" ) { echo '<div class="after">'; echo wp_split_more(get_post_field('post_content', get_the_ID()), 'after'); echo '</div>'; } echo '</div>'; -
vielhuber revised this gist
May 12, 2020 . 1 changed file with 30 additions and 25 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,33 +22,37 @@ function wp_split_more($content, $type, $more_html = null) // clean up // remove gutenberg tags foreach (['before', 'after'] as $g1__value) { foreach (['/', ''] as $g2__value) { foreach (['wp:paragraph', 'wp:more', 'wp:html'] as $g3__value) { $return[$g1__value] = str_replace( '<!-- ' . $g2__value . '' . $g3__value . ' -->', '', $return[$g1__value] ); } } } foreach ($return as $return__key => $return__value) { // remove whitespace $return[$return__key] = trim(preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $return[$return__key])); // remove all opening tags foreach (['<p></p>', '<p>', '</p>'] as $tags__value) { if (mb_strpos($return[$return__key], $tags__value) === 0) { $return[$return__key] = trim(mb_substr($return[$return__key], mb_strlen($tags__value))); } } // remove all closing tags foreach (['<p></p>', '<p>', '</p>'] as $tags__value) { if ( mb_strrpos($return[$return__key], $tags__value) === mb_strlen($return[$return__key]) - mb_strlen($tags__value) ) { $return[$return__key] = trim( mb_substr($return[$return__key], 0, mb_strlen($return[$return__key]) - mb_strlen($tags__value)) ); } } } @@ -60,12 +64,13 @@ function wp_split_more($content, $type, $more_html = null) // add opening / closing p-tags foreach ($return as $return__key => $return__value) { $return[$return__key] = (mb_strpos($return[$return__key], '<p') !== 0 ? '<p>' : '') . $return[$return__key] . (mb_strrpos($return[$return__key], '</p>') !== mb_strlen($return[$return__key]) - mb_strlen('</p>') ? '</p>' : ''); } return $return[$type]; } -
vielhuber revised this gist
Mar 27, 2020 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -26,6 +26,8 @@ function wp_split_more($content, $type, $more_html = null) $return['before'] = str_replace('<!-- /wp:paragraph -->', '', $return['before']); $return['before'] = str_replace('<!-- wp:more -->', '', $return['before']); $return['after'] = str_replace('<!-- /wp:more -->', '', $return['after']); $return['after'] = str_replace('<!-- wp:paragraph -->', '', $return['after']); $return['after'] = str_replace('<!-- /wp:paragraph -->', '', $return['after']); foreach ($return as $return__key => $return__value) { // remove whitespace $return[$return__key] = trim(preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $return[$return__key])); -
vielhuber revised this gist
Feb 20, 2020 . 1 changed file with 36 additions and 20 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,50 +5,66 @@ // with own function (wordpress own function has problems with enabled p tags) function wp_split_more($content, $type, $more_html = null) { $return = [ 'before' => null, 'after' => null ]; // split up if (preg_match('/<!--more(.*?)?-->/', $content, $matches)) { list($return['before'], $return['after']) = explode($matches[0], $content, 2); } else { $return['before'] = $content; $return['after'] = ''; } // clean up // remove gutenberg tags $return['before'] = str_replace('<!-- wp:paragraph -->', '', $return['before']); $return['before'] = str_replace('<!-- /wp:paragraph -->', '', $return['before']); $return['before'] = str_replace('<!-- wp:more -->', '', $return['before']); $return['after'] = str_replace('<!-- /wp:more -->', '', $return['after']); foreach ($return as $return__key => $return__value) { // remove whitespace $return[$return__key] = trim(preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $return[$return__key])); // remove falsly opening p tag if (strpos($return[$return__key], '</p>') === 0) { $return[$return__key] = trim(substr($return[$return__key], strlen('</p>'))); } // remove opening p tag if (strpos($return[$return__key], '<p>') === 0) { $return[$return__key] = trim(substr($return[$return__key], strlen('<p>'))); } // remove closing p tag if (strrpos($return[$return__key], '<p>') === strlen($return[$return__key]) - strlen('<p>')) { $return[$return__key] = trim( substr($return[$return__key], 0, strlen($return[$return__key]) - strlen('<p>')) ); } if (strrpos($return[$return__key], '</p>') === strlen($return[$return__key]) - strlen('</p>')) { $return[$return__key] = trim( substr($return[$return__key], 0, strlen($return[$return__key]) - strlen('</p>')) ); } } // add more tag if ($more_html !== null && $return['after'] !== '') { $return['before'] = $return['before'] . '' . $more_html; } // add opening / closing p-tags foreach ($return as $return__key => $return__value) { $return[$return__key] = (strpos($return[$return__key], '<p>') !== 0 ? '<p>' : '') . $return[$return__key] . (strrpos($return[$return__key], '</p>') !== strlen($return[$return__key]) - mb_strlen('</p>') ? '</p>' : ''); } return $return[$type]; } // example usage -
vielhuber revised this gist
Aug 20, 2018 . 1 changed file with 16 additions and 11 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,35 +8,40 @@ function wp_split_more($content, $type, $more_html = null) { $return = [ 'before' => null, 'after' => null ]; // split up if ( preg_match('/<!--more(.*?)?-->/', $content, $matches) ) { list($return['before'], $return['after']) = explode($matches[0], $content, 2); } else { $return['before'] = $content; $return['after'] = ''; } // clean up // remove gutenberg tags $return['before'] = str_replace('<!-- wp:paragraph -->','',$return['before']); $return['before'] = str_replace('<!-- /wp:paragraph -->','',$return['before']); $return['before'] = str_replace('<!-- wp:more -->','',$return['before']); $return['after'] = str_replace('<!-- /wp:more -->','',$return['after']); foreach($return as $key=>$value) { // remove whitespace $return[$key] = trim(preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $return[$key])); // remove falsly opening p tag if( strpos($return[$key], '</p>') === 0 ) { $return[$key] = trim(substr($return[$key], strlen('</p>'))); } // remove opening p tag if( strpos($return[$key], '<p>') === 0 ) { $return[$key] = trim(substr($return[$key], strlen('<p>'))); } // remove closing p tag if( strrpos($return[$key], '<p>') === strlen($return[$key])-strlen('<p>') ) { $return[$key] = trim(substr($return[$key], 0, strlen($return[$key])-strlen('<p>'))); } if( strrpos($return[$key], '</p>') === strlen($return[$key])-strlen('</p>') ) { $return[$key] = trim(substr($return[$key], 0, strlen($return[$key])-strlen('</p>'))); } } // add more tag if( $more_html !== null && $return['after'] !== '' ) { $return['before'] = $return['before'].''.$more_html; } // add opening / closing p-tags -
vielhuber revised this gist
May 14, 2018 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -40,8 +40,8 @@ function wp_split_more($content, $type, $more_html = null) { } // add opening / closing p-tags $return['before'] = (($return['before'][0] != '<')?('<p>'):('')).$return['before'].(($return['before'][strlen($return['before'])-1] != '>')?('</p>'):('')); $return['after'] = (($return['after'][0] != '<')?('<p>'):('')).$return['after'].(($return['after'][strlen($return['after'])-1] != '>')?('</p>'):('')); return $return[$type]; } -
vielhuber revised this gist
Dec 10, 2016 . No changes.There are no files selected for viewing
-
vielhuber revised this gist
Aug 28, 2016 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -49,11 +49,11 @@ function wp_split_more($content, $type, $more_html = null) { // example usage echo '<div class="content">'; echo '<div class="before">'; echo wp_split_more(get_post_field('post_content', get_the_ID()), 'before', '<a href="'.get_permalink(get_the_ID()).'" class="more">>>></a>'); echo '</div>'; if( wp_split_more(get_post_field('post_content', get_the_ID()), 'after') !== null && wp_split_more(get_post_field('post_content', get_the_ID()), 'after') != "" ) { echo '<div class="after">'; echo wp_split_more(get_post_field('post_content', get_the_ID()), 'after'); echo '</div>'; echo '</div>'; } -
vielhuber revised this gist
Jun 25, 2016 . 1 changed file with 7 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,19 +24,19 @@ function wp_split_more($content, $type, $more_html = null) { // clean up foreach($return as $key=>$value) { // remove whitespace $return[$key] = trim(preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $return[$key])); // remove falsly opening p tag if( strpos($return[$key], "</p>") === 0 ) { $return[$key] = trim(substr($return[$key], strlen("</p>"))); } // remove opening p tag if( strpos($return[$key], "<p>") === 0 ) { $return[$key] = trim(substr($return[$key], strlen("<p>"))); } // remove closing p tag if( strrpos($return[$key], "<p>") === strlen($return[$key])-strlen("<p>") ) { $return[$key] = trim(substr($return[$key], 0, strlen($return[$key])-strlen("<p>"))); } if( strrpos($return[$key], "</p>") === strlen($return[$key])-strlen("</p>") ) { $return[$key] = trim(substr($return[$key], 0, strlen($return[$key])-strlen("</p>"))); } } // add more tag if( $more_html !== null && $return["after"] !== "" ) { $return["before"] = $return["before"]."".$more_html; } // add opening / closing p-tags -
vielhuber revised this gist
Jun 25, 2016 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -29,7 +29,8 @@ function wp_split_more($content, $type, $more_html = null) { if( strpos($return[$key], "</p>") === 0 ) { $return[$key] = substr($return[$key], strlen("</p>")); } // remove opening p tag if( strpos($return[$key], "<p>") === 0 ) { $return[$key] = substr($return[$key], strlen("<p>")); } // remove falsly closing p tag if( strrpos($return[$key], "<p>") === strlen($return[$key])-strlen("<p>") ) { $return[$key] = substr($return[$key], 0, strlen($return[$key])-strlen("<p>")); } if( strrpos($return[$key], "</p>") === strlen($return[$key])-strlen("</p>") ) { $return[$key] = substr($return[$key], 0, strlen($return[$key])-strlen("</p>")); } } @@ -48,7 +49,7 @@ function wp_split_more($content, $type, $more_html = null) { // example usage echo '<div class="content">'; echo '<div class="before">'; echo wp_split_more($p->post_content, 'before', '<a href="'.get_permalink($p->post_id).'" class="more">>>></a>'); echo '</div>'; if( wp_split_more($p->post_content, 'after') !== null && wp_split_more($p->post_content, 'after') != "" ) { echo '<div class="after">'; -
vielhuber revised this gist
Jun 20, 2016 . 1 changed file with 50 additions and 24 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,29 +5,55 @@ // with own function (wordpress own function has problems with enabled p tags) function wp_split_more($content, $type, $more_html = null) { $return = [ "before" => null, "after" => null ]; // split up if ( preg_match('/<!--more(.*?)?-->/', $content, $matches) ) { list($return["before"], $return["after"]) = explode($matches[0], $content, 2); } else { $return["before"] = $content; $return["after"] = ''; } // clean up foreach($return as $key=>$value) { // remove whitespace $return[$key] = preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $return[$key]); // remove falsly opening p tag if( strpos($return[$key], "</p>") === 0 ) { $return[$key] = substr($return[$key], strlen("</p>")); } // remove opening p tag if( strpos($return[$key], "<p>") === 0 ) { $return[$key] = substr($return[$key], strlen("<p>")); } // remove closing p tag if( strrpos($return[$key], "</p>") === strlen($return[$key])-strlen("</p>") ) { $return[$key] = substr($return[$key], 0, strlen($return[$key])-strlen("</p>")); } } // add more tag if( $more_html !== null && $return["after"] !== "" ) { $return["before"] = $return["before"]." ".$more_html; } // add opening / closing p-tags $return["before"] = "<p>".$return["before"]."</p>"; $return["after"] = "<p>".$return["after"]."</p>"; return $return[$type]; } // example usage echo '<div class="content">'; echo '<div class="before">'; echo wp_split_more($p->post_content, 'before', '<a href="#" class="more">>>></a>'); echo '</div>'; if( wp_split_more($p->post_content, 'after') !== null && wp_split_more($p->post_content, 'after') != "" ) { echo '<div class="after">'; echo wp_split_more($p->post_content, 'after'); echo '</div>'; echo '</div>'; } ?> -
vielhuber revised this gist
Jun 20, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ // with own function (wordpress own function has problems with enabled p tags) function wp_split_more($content) { // split up if ( preg_match('/<!--more(.*?)?-->/', $content, $matches) ) { -
vielhuber revised this gist
Jun 20, 2016 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,14 +4,15 @@ echo get_extended($p->post_content)['extended']; // with own function (wordpress own function has problems with enabled p tags) function wp_split_content($content) { // split up if ( preg_match('/<!--more(.*?)?-->/', $content, $matches) ) { list($before, $after) = explode($matches[0], $content, 2); $more_text = $matches[1]; } else { $before = $content; $after = ''; $more_text = ''; -
vielhuber revised this gist
Jun 20, 2016 . No changes.There are no files selected for viewing
-
vielhuber revised this gist
May 24, 2016 . 1 changed file with 28 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,32 @@ <?php // with wordpress native functions echo get_extended($p->post_content)['main']; echo get_extended($p->post_content)['extended']; // outside of wordpress with own function function wp_split_content($content) { // split up if ( preg_match('/<!--more(.*?)?-->/', $content, $matches) ) { list($before, $after) = explode($matches[0], $content, 2); $more_text = $matches[1]; } else { $before = $content; $after = ''; $more_text = ''; } // remove whitespace $before = preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $before); $after = preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $after); $more_text = preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $more_text); return [ 'before' => $before, 'after' => $after, 'more_text' => $more_text ]; } ?> -
vielhuber renamed this gist
Sep 9, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
vielhuber created this gist
Sep 9, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ <?php echo get_extended($p->post_content)['main']; echo get_extended($p->post_content)['extended']; ?>