我创建了我自己的WordPress插件与小部件,我的问题是,当我在我的widgetname_widget. php修改一半的修改不适用.
我的代码:
class Blocs_Home_HS_Widget extends WP_Widget {
public function __construct() {
parent::__construct('blocshomehswidget', 'Blocs Home (version mobile)', array('description' => 'Gestion du contenu des blocs de la page d\'accueil version mobile'));
}
public function widget($args, $instance) {
$strReturn = disposition_blocs_home_handheld(array('sport_title' => $instance['sport_title'], 'sport_content' => $instance['sport_content'], 'sante_title' => $instance['sante_title'], 'sante_content' => $instance['sante_content'], 'be_title' => $instance['be_title'], 'be_content' => $instance['be_content'], 'recup_title' => $instance['recup_title'], 'recup_content' => $instance['recup_content']));
echo $strReturn;
}
public function form($instance) {
$sport_title = isset($instance['sport_title']) ? $instance['sport_title'] : '';
$sport_content = isset($instance['sport_content']) ? $instance['sport_content'] : '';
$sante_title = isset($instance['sante_title']) ? $instance['sante_title'] : '';
$sante_content = isset($instance['sante_content']) ? $instance['sante_content'] : '';
$be_title = isset($instance['be_title']) ? $instance['be_title'] : '';
$be_content = isset($instance['be_content']) ? $instance['be_content'] : '';
$recup_title = isset($instance['recup_title']) ? $instance['recup_title'] : '';
$recup_content = isset($instance['recup_content']) ? $instance['recup_content'] : '';
?>
<p>
<label for="<?php echo $this->get_field_name('sport_title');?>"><?php _e('Titre du bloc sport : ');?></label>
<input class="widefat" id="<?php echo $this->get_field_id('sport_title');?>" name="<?php echo $this->get_field_name('sport_title');?>" type="text" value="<?php echo $sport_title;?>" />
</p>
<p>
<label for="<?php echo $this->get_field_name('sport_content');?>"><?php _e('Contenu du bloc sport (max 56 caratères par ligne, max 280 au total) : ');?></label>
<input class="widefat" id="<?php echo $this->get_field_id('sport_content');?>" name="<?php echo $this->get_field_name('sport_content');?>" type="text" value="<?php echo $sport_content;?>" />
</p>
<p>
<label for="<?php echo $this->get_field_name('sante_title');?>"><?php _e('Titre du bloc santé :');?></label>
<input class="widefat" id="<?php echo $this->get_field_id('sante_title');?>" name="<?php echo $this->get_field_name('sante_title');?>" type="text" value="<?php echo $sante_title;?>" />
</p>
<p>
<label for="<?php echo $this->get_field_name('sante_content');?>"><?php _e('Contenu du bloc santé (max 56 caratères par ligne, max 280 au total) :');?></label>
<input class="widefat" id="<?php echo $this->get_field_id('sante_content');?>" name="<?php echo $this->get_field_name('sante_content');?>" type="text" value="<?php echo $sante_content;?>" />
</p>
<p>
<label for="<?php echo $this->get_field_name('be_title');?>"><?php _e('Titre du bloc bien-être :');?></label>
<input class="widefat" id="<?php echo $this->get_field_id('be_title');?>" name="<?php echo $this->get_field_name('be_title');?>" type="text" value="<?php echo $be_title;?>" />
</p>
<p>
<label for="<?php echo $this->get_field_name('be_content');?>"><?php _e('Contenu du bloc bien-être (max 56 caratères par ligne, max 280 au total) :');?></label>
<input class="widefat" id="<?php echo $this->get_field_id('be_content');?>" name="<?php echo $this->get_field_name('be_content');?>" type="text" value="<?php echo $be_content;?>" />
</p>
<p>
<label for="<?php echo $this->get_field_name('recup_title');?>"><?php _e('Titre du bloc récupération :');?></label>
<input class="widefat" id="<?php echo $this->get_field_id('recup_title');?>" name="<?php echo $this->get_field_name('recup_title');?>" type="text" value="<?php echo $recup_title;?>" />
</p>
<p>
<label for="<?php echo $this->get_field_name('recup_content');?>"><?php _e('Contenu du bloc récupération (max 56 caratères par ligne, max 280 au total) :');?></label>
<input class="widefat" id="<?php echo $this->get_field_id('recup_content');?>" name="<?php echo $this->get_field_name('recup_content');?>" type="text" value="<?php echo $recup_content;?>" />
</p>
<?php
}
public function random_pos_handheld($param) {
$toReturn = array();
$tempId = '';
$tempTitle = '';
$tempContent = '';
$logRand = array();
for($i = 0; $i < 4; $i++) {
$random = rand(0, 3);
if(in_array($random, $logRand)) {
$i--;
}
else {
array_push($logRand, $random);
switch($random) {
case 0:
$tempId = 'sport';
$tempTitle = $param['sport_title'];
$tempContent = $param['sport_content'];
break;
case 1:
$tempId = 'sante';
$tempTitle = $param['sante_title'];
$tempContent = $param['sante_content'];
break;
case 2:
$tempId = 'be';
$tempTitle = $param['be_title'];
$tempContent = $param['be_content'];
break;
case 3:
$tempId = 'recup';
$tempTitle = $param['recup_title'];
$tempContent = $param['recup_content'];
break;
default:
}
$toReturn[$i] = array(
'id' => $tempId,
'bloc' => $i,
'title' => $tempTitle,
'content' => $tempContent
);
}
}
return $toReturn;
}
public function disposition_blocs_home_handheld($param) {
$result = random_pos_handheld($param);
$strReturn = '';
foreach($result as $elt) {
$strReturn .= '<div class="pos_absolute bloc_' . $elt['id'] . '_hs bloc_' . $elt['bloc'] . '">
<img src="wp-content/themes/pulsdesign/images/bloc_' . $elt['id'] . '_hs.jpg" class="pos_absolute float_right img_bloc_home" />
<img src="wp-content/themes/pulsdesign/images/segment_bloc_hs_home.png" class="pos_absolute segment_bloc_hs_home" />
<p class="pos_absolute bloc_p_title_hs fsize4p4 p_blanc">' . $elt['title'] . '</p>
<p class="pos_absolute bloc_p_content fsize39 p_blanc">' . $elt['content'] . '</p>
<img src="wp-content/themes/pulsdesign/images/bouton_fade.png" class="button_bloc_solutions_hs pos_absolute" />
<p class="pos_absolute text_bloc_solutions_hs p_blanc fsize30"><b>Nos solutions</b></p>
<a href="/testimonies_' . $elt['id'] . '">
<img src="wp-content/themes/pulsdesign/images/bouton_fade.png" class="button_bloc_temoignage_hs pos_absolute" />
<p class="pos_absolute text_bloc_temoignage_hs p_blanc fsize30"><b>Témoignages<br />clients</b></p>
</a>
<img src="wp-content/themes/pulsdesign/images/bouton_fade.png" class="button_bloc_sp_articles_hs pos_absolute" />
<p class="pos_absolute text_bloc_articles_hs p_blanc fsize30"><b>Articles</b></p>
</div>';
}
return $strReturn;
}
}
当我修改函数widget()
、form()
和构造函数时,没有问题,我重新加载页面(包含小部件)并应用修改。
但是当我修改我创建的函数(random_pos_handheld()
和disposition_blocs_home_handheld()
)时,什么都没有...我试图重新加载页面,停用并重新激活插件,重新安装最后的WordPress更新...没有什么。我想我必须强制重新加载widget_init
,但我在互联网上没有找到任何东西。
1条答案
按热度按时间e4eetjau1#
好吧,新手犯的大错…解决办法是。。用
$this->function()
!