Last active
December 29, 2018 14:43
-
-
Save radarin/f673692d5f6c9fca690c980ef583341c to your computer and use it in GitHub Desktop.
Auszug und Inhalt vergleichen
This file contains 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 characters
<?php | |
// Auszug und Inhalt vergleichen | |
function vs_excerpt_content(){ | |
global $post; | |
// Auszug laden | |
$auszug = get_the_excerpt($post->ID); | |
// HTML und PHP entfernen | |
$auszug = strip_tags($auszug); | |
// Shortcodes entfernen | |
$auszug = strip_shortcodes($auszug); | |
// Wandelt alle Buchstaben in Kleinbuchstaben um. | |
// Wordpress schreibt sich im Auszug automatisch WordPress, | |
// was zu einem Fehler beim Vergleich führt, wenn Wordpress | |
// im Inhalt vorhanden ist | |
$auszug = strtolower($auszug); | |
// Leerzeichen entfernen | |
$auszug = str_replace(" ", "", $auszug); | |
$inhalt = get_the_content($post->ID); | |
$inhalt = strip_tags($inhalt); | |
$inhalt = strip_shortcodes($inhalt); | |
$inhalt = strtolower($inhalt); | |
$inhalt = str_replace(" ", "", $inhalt); | |
// Zeilenumbrüche und Absätze entfernen | |
// Die Funktion get_the_excerpt() hat dies bereits erledigt | |
// Die Funktion get_the_content() liefert Diese noch mit | |
$inhalt = str_replace("\r", "", $inhalt); | |
$inhalt = str_replace("\n", "", $inhalt); | |
if($auszug != $inhalt) { | |
// hier Original Link aus dem Theme einfügen. Im Theme dafür statt des Links | |
// den Funktionsaufruf einfügen. >>> vs_excerpt_content(); | |
// Das hier verwendete Beispiel entspricht dem Theme 'Traverfly' | |
echo '<a class="readmore" href="' . get_permalink() . '" title="'.the_title( '', '', false ).'">'.__( 'Read more', 'travelify' ).'</a>'; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment