1
今天,我在我的functions.php
中創建了一個類,其中包含一些有關Wordpress帖子格式的屬性和方法。現在我的類包含一些關於引用帖子格式的代碼。但我不知道如何在其他Wordpress文件中使用YPE_QPA()
方法和icon
屬性。例如我如何在index.php
內使用此方法和屬性?在wordpress之外使用類方法和屬性(functions.php)
class YPE_post_formats {
public $icon = '<span class="pull-right glyphicon glyphicon-pause"></span>';
public function YPE_QPA() {
$quote_post = get_the_content();
$quote_post = wpautop($quote_post);
$quote_text = substr($quote_post, 0 , strpos($quote_post, '</p>') + 4);
$quote_text = strip_tags($quote_text, '<a><strong><em><i>');
}
}
$YPE_PFormats = new YPE_post_formats();
非常感謝你,因爲每個wordpress文件都可以訪問'functions.php'中的每個函數,不需要include_once('path/to/functions.php');但必須在'functions.php'之外創建類的實例或使用'global'關鍵字來訪問類實例 ' –