我正在尝试回应设置
$this->settings['numberofwordsexcerpt'] = array(
'title' => __( 'Number of Words' ),
'desc' => __( 'Please enter here the number of words you want the latest posts on index to have.' ),
'std' => '25',
'type' => 'text',
'section' => 'general'
);
在变量$word_limit
add_action('the_excerpt','limit_the_content');
function limit_the_content($content){
$word_limit = $this->settings['numberofwordsexcerpt']; // HERE I AM TRYING to echo it
但是不起作用,我收到错误
Fatal error: Using $this when not in object context
$words = explode(' ', $content); return implode(' ', array_slice($words, 0, $word_limit)); }
我也试过
$word_limit = $settings['numberofwordsexcerpt'];
我得到一个与变量$settings
未定义相关的错误...
也尝试了
$word_limit = ?> <?php echo $settings['numberofwordsexcerpt']; ?>
并获得与";",
相关的错误,尝试删除该错误但仍然存在错误。请帮忙。
答案 0 :(得分:3)
$settings = get_option('mytheme_options');
$word_limit = $settings['numberofwordsexcerpt'];
echo $word_limit;