您试图将PHP粘贴到文本小部件中。标签已经被转换了。
<div class="textwidget"> <!--?php if (is_category(\'5\')) { ?-->
默认情况下,您不能从文本小部件执行PHP,我不建议尝试这样做(这应该是可能的)。相反
it is trivial to build your own widget to do this.
根据另一个答案:
class PHP_Widget_wpse_135949 extends WP_Widget {
function __construct() {
$opts = array(
\'description\' => \'Display Some ads\'
);
parent::WP_Widget(
\'my-ad-content\',
\'Some PHP\',
$opts
);
}
function widget($args,$instance) {
// Your PHP goes here
//
echo \'PHP generated content\';
}
}
function register_my_widgets() {
register_widget(\'PHP_Widget_wpse_135949\');
}
add_action(\'widgets_init\',\'register_my_widgets\');