Ich habe eine Klasse geändert, die ich auf Stack Overflow für verschiedene Wordpress Auszugslänge gefunden habe. Es war ein Bär (seit ich neu bei OOP bin), aber es funktioniert schließlich und akzeptiert nun einen zweiten Parameter, um den Link mehr lesen zu filtern. Was ich aber gerne machen würde, ist zur Zeit die Ausgabe 'the_excerpt', die sofort dort herauskommt, wo die Funktion "my_excerpt()" aufgerufen wird. Ich möchte eine Funktion namens "get_my_excerpt" hinzufügen, die den Wert zurückgibt. Ich weiß, dass get_the_excerpt() genau das tut, aber ich kann nicht scheinen, dass es in dieser Klasse funktioniert.return get_the_excerpt() aus einer Klasse für mehrere Wordpress-Auszüge
/* Class that enables excerpt length parameter */
/* called via my_excerpt('length') */
class Excerpt {
// Default length (by WordPress)
public static $length = 55;
// Default more (by WordPress)
public static $more = "[...]";
// So you can call: my_excerpt('short');
public static $types = array(
'short' => 25,
'regular' => 55,
'long' => 100,
'xlong' => 200,
);
// So you can call: my_excerpt('short');
public static $more_types = array(
'none' => "",
'regular' => "[...]",
'ellipse' => "...",
'permalink' => 'skip',
);
/**
* Sets the length for the excerpt,
* then it adds the WP filter
* And automatically calls the_excerpt();
*
* @param string $new_length
* @return void
* @author Baylor Rae'
*/
public static function filter($new_length = 55, $new_more="[...]", $echo=TRUE) {
Excerpt::$length = $new_length;
Excerpt::$more = $new_more;
add_filter('excerpt_length', 'Excerpt::new_length',98);
add_filter('excerpt_more', 'Excerpt::new_more',99);
return Excerpt::output();
}
// Tells WP the new length
public static function new_length() {
if(isset(Excerpt::$types[Excerpt::$length]))
return Excerpt::$types[Excerpt::$length];
else
return Excerpt::$length;
}
// Tells WP the new more
public static function new_more() {
$db = new ReadMore;
if(isset(Excerpt::$more_types[Excerpt::$more]) AND ((Excerpt::$more_types[Excerpt::$more]) != "skip"))
return Excerpt::$more_types[Excerpt::$more];
elseif(isset(Excerpt::$more_types[Excerpt::$more]) AND ((Excerpt::$more_types[Excerpt::$more]) == "skip"))
return $db->readmore();
else
return Excerpt::$more;
}
// Echoes out the excerpt
public static function output() {
return get_the_excerpt();
}
}
// An alias to the class
function get_my_excerpt($length = 55, $more="[...]") {
return Excerpt::filter($length, $more);
}
// An alias to the class
function my_excerpt($length = 55, $more="[...]") {
echo get_my_excerpt($length, $more);
}
class ReadMore {
private $title;
private $permalink;
private $more;
public function __construct() {
//$this->title = get_the_title();
//$this->permalink = get_permalink();
$temp = "..." . '<a class="readmore" title="'. _('Permalink to').get_the_title() . '" href=" ' . get_permalink() . '">'._('Read the rest').'</a>';
$this->more = $temp;
}
public function readmore() {
return $this->more;
}
}
JA! tat, was Sie sagten, plus addierte Rückkehr zur statischen Ausgabe() und jetzt funktioniert es. Ich habe meinen Code im ursprünglichen Beitrag korrigiert, um Ihre Änderungen widerzuspiegeln. Vielen Dank! – helgatheviking