I'm still quite a newbie developer so small problems like this bring me to a stand still from time to time.
I've basically built a custom plugin to display pdf images next to a link very basic I know, but my problem is I need the $title1 text to be a different colour on certain page templates so I'm trying to alter the output code with a conditional but it doesn't seem to be parsed in the browser.
the code now been parsed if the conditional only the .menu-widget div gets output on all page templates instead of .white replacing it allowing me to style it with css.
the IMAGES Constant is defined within functions.php file.
Here is my code
class donor_pdf_plugin extends WP_Widget {
// Constructor
function donor_pdf_plugin() {
parent::WP_Widget(false, $name = __('Pdf footer description', 'donor_pdf_plugin'));
}
// Widget form creation
function form($instance) {
// Check values
if($instance) {
$link = esc_attr($instance['link']);
$link1 = esc_attr($instance['link1']);
$link2 = esc_attr($instance['link2']);
$link3 = esc_attr($instance['link3']);
$title = esc_attr($instance['title']);
$title1 = esc_attr($instance['title1']);
$title2 = esc_attr($instance['title2']);
$title3 = esc_attr($instance['title3']);
} else {
$link = '';
$link1 = '';
$link2 = '';
$link3 = '';
$title = '';
$title1 = '';
$title2 = '';
$title3 = '';
}
?>
<p>
<label for="<?php echo $this->get_field_id('link'); ?>"><?php _e('Menu link', 'wp_widget_plugin'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('link'); ?>" name="<?php echo $this->get_field_name('link'); ?>" type="text" value="<?php echo $link; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('link1'); ?>"><?php _e('Menu link1', 'wp_widget_plugin'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('link1'); ?>" name="<?php echo $this->get_field_name('link1'); ?>" type="text" value="<?php echo $link1; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('link2'); ?>"><?php _e('Menu link2', 'wp_widget_plugin'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('link2'); ?>" name="<?php echo $this->get_field_name('link2'); ?>" type="text" value="<?php echo $link2; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('link3'); ?>"><?php _e('Menu link3', 'wp_widget_plugin'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('link3'); ?>" name="<?php echo $this->get_field_name('link3'); ?>" type="text" value="<?php echo $link3; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Menu title', 'wp_widget_plugin'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('title1'); ?>"><?php _e('Menu title1', 'wp_widget_plugin'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title1'); ?>" name="<?php echo $this->get_field_name('title1'); ?>" type="text" value="<?php echo $title1; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('title2'); ?>"><?php _e('Menu title2', 'wp_widget_plugin'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title2'); ?>" name="<?php echo $this->get_field_name('title2'); ?>" type="text" value="<?php echo $title2; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('title3'); ?>"><?php _e('Menu title3', 'wp_widget_plugin'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title3'); ?>" name="<?php echo $this->get_field_name('title3'); ?>" type="text" value="<?php echo $title3; ?>" />
</p>
<?php // end of widget form creation ?>
<?php
}
// Widget update
function update($new_instance, $old_instance) {
$instance = $old_instance;
// Fields
$instance['link'] = strip_tags($new_instance['link']);
$instance['link1'] = strip_tags($new_instance['link1']);
$instance['link2'] = strip_tags($new_instance['link2']);
$instance['link3'] = strip_tags($new_instance['link3']);
$instance['title'] = strip_tags($new_instance['title']);
$instance['title1'] = strip_tags($new_instance['title1']);
$instance['title2'] = strip_tags($new_instance['title2']);
$instance['title3'] = strip_tags($new_instance['title3']);
return $instance;
}
// Widget display
function widget($args, $instance) {
extract($args);
$link = $instance['link'];
$link1 = $instance['link1'];
$link2 = $instance['link2'];
$link3 = $instance['link3'];
$title = $instance['title'];
$title1 = $instance['title1'];
$title2 = $instance['title2'];
$title3 = $instance['title3'];
if(!is_home()) {
echo "<div class=\"menu-widget\">
<p><a href=\"$link\"><img src=\"" . IMAGES . "/pdf.png\"/><span class=\"pdf-description\"> $title</a></p>
<p><a href=\"$link1\"><img src=\"" . IMAGES . "/pdf.png\"/><span class=\"pdf-description\">$title1</span></a></p>
<p><a href=\"$link2\"><img src=\"" . IMAGES . "/pdf.png\"/><span class=\"pdf-description\">$title2</a></p>
<p><a href=\"$link3\"><img src=\"" . IMAGES . "/pdf.png\"/><span class=\"pdf-description\">$title3</a></p>
</div>";
} else {
echo "<div class=\"white\">
<p><a href=\"$link\"><img src=\"" . IMAGES . "/pdf.png\"/><span class=\"pdf-description\"> $title</a></p>
<p><a href=\"$link1\"><img src=\"" . IMAGES . "/pdf.png\"/><span class=\"pdf-description\">$title1</span></a></p>
<p><a href=\"$link2\"><img src=\"" . IMAGES . "/pdf.png\"/><span class=\"pdf-description\">$title2</a></p>
<p><a href=\"$link3\"><img src=\"" . IMAGES . "/pdf.png\"/><span class=\"pdf-description\">$title3</a></p>
</div>";
}
}
}
// Register widget
add_action('widgets_init', create_function('', 'return register_widget("donor_pdf_plugin");'));
?>
the code not been parsed is this bit.
} else {
echo "<div class=\"white\">
<p><a href=\"$link\"><img src=\"" . IMAGES . "/pdf.png\"/><span class=\"pdf-description\"> $title</a></p>
<p><a href=\"$link1\"><img src=\"" . IMAGES . "/pdf.png\"/><span class=\"pdf-description\">$title1</span></a></p>
<p><a href=\"$link2\"><img src=\"" . IMAGES . "/pdf.png\"/><span class=\"pdf-description\">$title2</a></p>
<p><a href=\"$link3\"><img src=\"" . IMAGES . "/pdf.png\"/><span class=\"pdf-description\">$title3</a></p>
</div>";
}
IMAGES
constant set?is_home()
and notis_front_page()
I.E. is your home page a static page?is_home
can't work for you, as I guessed.