在Wordpress CMS中重新定义“部件”功能

时间:2018-06-22 17:16:19

标签: php wordpress

现在,我创建一个新的简单wordpress主题。

请告诉我,如何重新定义文件中定义的 widget 公共功能?: wordpress-dir / wp-includes / widgets / class-wp-widget-tag-cloud。 php

所以我需要删除<div class="tagcloud"> html标记而不编辑核心 WP 文件。

我尝试了什么:在主题的 functions.php 中,我定义了一个名为new_widget的新函数(带有参数$args, $instance),在下面插入了要运行的代码并称为add_filter('widget', 'new_widget');

$current_taxonomy = $this->_get_current_taxonomy( $instance );

if ( ! empty( $instance['title'] ) ) {
  $title = $instance['title'];
} else {
  if ( 'post_tag' === $current_taxonomy ) {
    $title = __( 'Tags' );
  } else {
    $tax = get_taxonomy( $current_taxonomy );
    $title = $tax->labels->name;
  }
}

$show_count = ! empty( $instance['count'] );

/**
* Filters the taxonomy used in the Tag Cloud widget.
*
* @since 2.8.0
* @since 3.0.0 Added taxonomy drop-down.
* @since 4.9.0 Added the `$instance` parameter.
*
* @see wp_tag_cloud()
*
* @param array $args     Args used for the tag cloud widget.
* @param array $instance Array of settings for the current widget.
*/
$tag_cloud = wp_tag_cloud( apply_filters( 'widget_tag_cloud_args', array(
  'taxonomy'   => $current_taxonomy,
  'echo'       => false,
  'show_count' => $show_count,
), $instance ) );

if ( empty( $tag_cloud ) ) {
  return;
}

/** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
$title = apply_filters( 'widget_title', $title, $instance, $this->id_base );

echo $args['before_widget'];
if ( $title ) {
  echo $args['before_title'] . $title . $args['after_title'];
}

echo $tag_cloud;

echo $args['after_widget'];
function glurion_widget( $args, $instance ) {
  $current_taxonomy = $this->_get_current_taxonomy( $instance );

if ( ! empty( $instance['title'] ) ) {
  $title = $instance['title'];
} else {
  if ( 'post_tag' === $current_taxonomy ) {
   $title = __( 'Tags' );
  } else {
    $tax = get_taxonomy( $current_taxonomy );
    $title = $tax->labels->name;
  }
}

$show_count = ! empty( $instance['count'] );

/**
* Filters the taxonomy used in the Tag Cloud widget.
*
* @since 2.8.0
* @since 3.0.0 Added taxonomy drop-down.
* @since 4.9.0 Added the `$instance` parameter.
*
* @see wp_tag_cloud()
*
* @param array $args     Args used for the tag cloud widget.
* @param array $instance Array of settings for the current widget.
*/
$tag_cloud = wp_tag_cloud( apply_filters( 'widget_tag_cloud_args', array(
  'taxonomy'   => $current_taxonomy,
  'echo'       => false,
  'show_count' => $show_count,
 ), $instance ) );

if ( empty( $tag_cloud ) ) {
  return;
}

/** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
$title = apply_filters( 'widget_title', $title, $instance, $this->id_base );

echo $args['before_widget'];
if ( $title ) {
  echo $args['before_title'] . $title . $args['after_title'];
}

/** Commented: echo '<div class="tagcloud">'; */

echo $tag_cloud;

/** Commented: echo "</div>\n"; */
echo $args['after_widget'];

所以...在wordpress页面的标签云中,我看到了已删除的html标签。

0 个答案:

没有答案