Support » Plugins » [Plugin: SidePosts Widget] How to remove “Archive for X” in SidePosts widget?

  • I’d like to remove the “Archive for X” notice (and RSS icon) in the SidePosts widget. (I’ve searched forums and can’t find exactly this issue.) I’m using SidePosts with the Chameleon theme by Alkivia.

    Any help greatly appreciated!

    Thank you.

Viewing 6 replies - 1 through 6 (of 6 total)
  • This text is hardcoded on the plugin and cannot be removed without hacking it.

    Thread Starter ridgewoodneighbor

    (@ridgewoodneighbor)

    Thank you. 🙂

    Does anyone know if there is some specific code I can remove or change in the widgets.php file? (Or another file?)

    Here’s the widgets.php file below (fantastic SidePosts widget by Txanny at Alkivia.org):

    <?php

    /**

    * SidePosts WordPress Widget.

    *

    * WordPress widget to move post from a category to the sidebar.

    * Posts will not show on index pages, archives or feeds. The category has its own feed.

    *

    * @version $Rev: 117381 $

    * @author Jordi Canals

    * @package SidePosts

    * @link http://alkivia.org/plugins/sideposts

    * @license http://www.gnu.org/licenses/gpl.html GNU General Public License v3

    Copyright 2008-2009 Jordi Canals <gpl@alkivia.com>

    This program is free software: you can redistribute it and/or modify

    it under the terms of the GNU General Public License as published by

    the Free Software Foundation, either version 3 of the License, or

    (at your option) any later version.

    This program is distributed in the hope that it will be useful,

    but WITHOUT ANY WARRANTY; without even the implied warranty of

    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License

    along with this program. If not, see <http://www.gnu.org/licenses/&gt;.

    */

    require_once ( dirname(__FILE__) . ‘/framework/plugins.php’ );

    require_once ( dirname(__FILE__) . ‘/framework/widgets.php’ );

    /**

    * SidePosts Class.

    * Manages all plugin features.

    *

    * @author Jordi Canals

    * @package SidePosts

    * @link http://alkivia.org

    */

    class akvSidePosts extends spostsPlugin

    {

    /**

    * Updates widget info when updating the widget.

    * Deletes information from old versions, as it is incompatible with current version.

    *

    * @return void

    */

    protected function update() {

    $ver = get_option($this->ID . ‘_version’);

    if ( false !== $ver && version_compare($ver, ‘2.0’, ‘<‘) ) {

    // Updating from versions prior to 2.0, requires deleting old incopatible data.

    akv_remove_widget($this->ID); // Remove widget from sidebars.

    delete_option($this->ID . ‘_widget’); // Delete Sideposts Options.

    }

    }

    /**

    * Inits the widget and prepares parameters.

    * Registers widget at sidebar and admin panels.

    *

    * @return void

    */

    protected function widgetsInit() {

    add_action(‘pre_get_posts’, array(&$this, ‘_postsFilter’ ));

    if ( ! $options = get_option($this->ID . ‘_widget’) ) {

    $options = array();

    }

    $widget_ops = array(‘classname’ => ‘widget_sideposts’, ‘description’ => __(‘A widget to move posts to the sidebar.’, $this->ID) );

    $control_ops = array(‘id_base’ => $this->ID);

    $registered = false;

    foreach ( array_keys($options) as $o ) {

    $id = “{$this->ID}-{$o}”; // $id should look like {$id_base}-{$o}

    $registered = true;

    wp_register_sidebar_widget( $id, $this->p_data[‘Name’], array(&$this, ‘_widget’), $widget_ops, array(‘number’ => $o) );

    wp_register_widget_control( $id, $this->p_data[‘Name’], array(&$this, ‘_widgetControl’), $control_ops, array(‘number’ => $o) );

    }

    // If there are none, we register the widget’s existance with a generic template

    if ( !$registered ) {

    wp_register_sidebar_widget( “{$this->ID}-1”, $this->p_data[‘Name’], array(&$this, ‘_widget’), $widget_ops, array(‘number’ => -1) );

    wp_register_widget_control( “{$this->ID}-1”, $this->p_data[‘Name’], array(&$this, ‘_widgetControl’), $control_ops, array(‘number’ => -1) );

    }

    }

    /**

    * Sidebar widget to show posts.

    * Prints al posts of the sideposts category in the sidebar.

    *

    * @uses apply_filters() Calls the ‘sideposts_date’ hook on post date.

    * @hook wp_register_sidebar_widget

    * @param array $args Widget arguments.

    * @param array|int $widget_args Widget number. Which of the several widgets of this type do we mean.

    * @return void

    */

    function _widget( $args, $widget_args = 1 ) {

    $this->savePost(); // Save current post data.

    extract( $args, EXTR_SKIP );

    if ( is_numeric($widget_args) ) {

    $widget_args = array( ‘number’ => $widget_args );

    }

    $widget_args = wp_parse_args( $widget_args, array( ‘number’ => -1 ) );

    extract( $widget_args, EXTR_SKIP );

    $options = get_option($this->ID . ‘_widget’);

    if ( ! isset($options[$number]) ) { // No instances of this widget

    return;

    }

    if ( -99 == (int) $options[$number][‘category’] && ! current_user_can(‘read_private_posts’) ) {

    return; // Widget is for private posts and user cannot see them

    }

    $numposts = (int) $options[$number][‘numposts’];

    if ( 1 > $numposts ) { // Defaults to 3 posts on sidebar

    $numposts = 3;

    } elseif ( 20 < $numposts ) { // No more than 20 posts.

    $numposts = 20;

    }

    $category = (int) $options[$number][‘category’];

    if ( 0 == $category ) {

    _e(‘Category not selected.’, $this->ID);

    return;

    }

    echo $before_widget;

    if ( !empty($options[$number][‘title’]) ) {

    echo $before_title. $options[$number][‘title’] . $after_title;

    }

    echo ‘

      ‘;

    $sidequery = ( -99 == (int) $category )

    ? “post_status=private&showposts={$numposts}&caller_get_posts=1” // Private Posts

    : “cat={$category}&showposts={$numposts}”; // Category Posts

    $q = new WP_Query($sidequery);

    if ( $q->have_posts() ) {

    while ( $q->have_posts() ) {

    $q->the_post();

    echo ‘

    • ‘;
    • echo ‘‘. get_the_title() .’‘;

      if ( ‘title’ != $options[$number][‘show’]) {

      global $post;

      $date_string = ‘<span class=”sideposts_date”>’. mysql2date(get_option(‘date_format’), $post->post_date) . ‘ | ‘ . get_the_time() .'</span>’;

      echo ‘
      ‘ . apply_filters($this->ID . ‘_date’, $date_string);

      switch ( $options[$number][‘show’] ) {

      case ‘posts’ :

      global $more;

      $more = false;

      the_content(‘<p>’ . __(‘Read more »’, $this->ID) . ‘</p>’);

      break;

      case ‘ex-thumb’ :

      echo ‘<p>’. $this->excerptThumbnail($number) . get_the_excerpt() . ‘</p>’;

      echo ‘<p>‘. __(‘Read full post »’, $this->ID) .’</p>’;

      break;

      case ‘excerpt’ :

      the_excerpt();

      echo ‘<p>‘. __(‘Read full post »’, $this->ID) .’</p>’;

      break;

      }

      }

      echo ‘
      ‘;

      }

      } else {

      _e(‘No posts found’, $this->ID);

      }

      if ( -99 != (int) $category ) {

      echo ‘

    • ‘;
    • echo ‘<a href=”‘

      . get_category_feed_link($category) .'”><img style=”border:0;float:right;” src=”‘

      . $this->p_dirs[‘url’] . ‘rss.png” alt=”RSS” />’;

      echo ‘‘;

      _e(‘Archive for’, $this->ID);

      echo ‘ ‘. $options[$number][‘title’] .’ »
      ‘; // get_the_category_by_ID($category)

      }

      echo ‘
      ‘;

      echo $after_widget;

      $this->restorePost(); // Revert to the previous post status.

      }

      /**

      * Admin section for the widget.

      * Allows multiple instances of the widget.

      *

      * @hook wp_register_widget_control

      * @param array|int $widget_args Widget number. Which of the several widgets of this type do we mean.

      * @return void

      */

      function _widgetControl( $widget_args = 1 ) {

      global $wp_registered_widgets;

      static $updated = false; // Whether or not we have already updated the data after a POST submit

      if ( is_numeric($widget_args) ) {

      $widget_args = array( ‘number’ => $widget_args );

      }

      $widget_args = wp_parse_args( $widget_args, array( ‘number’ => -1 ) );

      extract( $widget_args, EXTR_SKIP );

      // Data should be stored as array: array( number => data for that instance of the widget, … )

      $options = get_option($this->ID . ‘_widget’);

      if ( ! is_array($options) ) {

      $options = array();

      }

      if ( ! $updated && ! empty($_POST[‘sidebar’]) ) { // We need to update the data

      $sidebar = (string) $_POST[‘sidebar’]; // Tells us what sidebar to put the data in

      $sidebars_widgets = wp_get_sidebars_widgets();

      if ( isset($sidebars_widgets[$sidebar]) ) {

      $this_sidebar =& $sidebars_widgets[$sidebar];

      } else {

      $this_sidebar = array();

      }

      foreach ( $this_sidebar as $_widget_id ) {

      // Remove all widgets of this type from the sidebar. We’ll add the new data in a second. This makes sure we don’t get any duplicate data

      // since widget ids aren’t necessarily persistent across multiple updates

      if ( $this->ID . ‘_widget’ == $wp_registered_widgets[$_widget_id][‘callback’] && isset($wp_registered_widgets[$_widget_id][‘params’][0][‘number’]) ) {

      $widget_number = $wp_registered_widgets[$_widget_id][‘params’][0][‘number’];

      if ( ! in_array( “{$this->ID}-{$widget_number}”, $_POST[‘widget-id’] ) ) {

      unset($options[$widget_number]); // the widget has been removed.

      }

      }

      }

      foreach ( (array) $_POST[‘sideposts’] as $widget_number => $widget_data ) {

      //compile data from $widget_many_instance

      if ( ! isset($widget_data[‘submit’]) && isset($options[$widget_number]) ) { // user clicked cancel

      continue;

      }

      $options[$widget_number][‘title’] = strip_tags(stripslashes($widget_data[‘title’]));

      $options[$widget_number][‘category’] = (int) $widget_data[‘category’];

      $options[$widget_number][‘numposts’] = (int) $widget_data[‘numposts’];

      $options[$widget_number][‘show’] = $widget_data[‘content’];

      $options[$widget_number][‘thumbnail’] = (int) $widget_data[‘thumbnail’];

      }

      update_option(‘sideposts_widget’, $options);

      $updated = true; // So that we don’t go through this more than once

      }

      // Here we echo out the form

      if ( -1 == $number ) { // We echo out a template with defaults for a form which can be converted to a specific form later via JS

      $s_title = ”;

      $s_category = 0;

      $s_numposts = 3;

      $s_show = ‘posts’;

      $s_thumbnail = 100;

      $number = ‘%i%’;

      } else {

      $s_title = attribute_escape($options[$number][‘title’]);

      $s_category = intval($options[$number][‘category’]);

      $s_numposts = intval($options[$number][‘numposts’]);

      $s_show = attribute_escape($options[$number][‘show’]);

      $s_thumbnail = intval($options[$number][‘thumbnail’]);

      }

      ?>

      <p><?php _e(‘Title:’, $this->ID); ?> <input class=”widefat” id=”sideposts-title” name=”sideposts[<?php echo $number; ?>][title]” type=”text” value=”<?php echo $s_title; ?>” /></p>

      <p><?php _e(‘Category:’, $this->ID); ?>

      <select name=”sideposts[<?php echo $number; ?>][category]” id=”sideposts-category” class=”widefat”>

      <option value=”-99″<?php selected(-99, (int) $s_category); ?>><?php _e(‘– PRIVATE POSTS –‘, $this->ID) ?></option>

      <?php

      $categories = get_terms(‘category’);

      foreach ( $categories as $cat ) {

      echo ‘<option value=”‘ . $cat->term_id .'”‘;

      selected((int) $cat->term_id, (int) $s_category);

      echo ‘>’ . $cat->name . ‘</option>’;

      }

      ?>

      </select>

      </p>

      <p>

      <?php _e(‘Number of posts:’, $this->ID); ?> <input style=”width: 30px;” id=”sideposts-numposts” name=”sideposts[<?php echo $number; ?>][numposts]” type=”text” value=”<?php echo $s_numposts; ?>” />

      <small><?php printf(__(‘(At most %d)’, $this->ID), 20); ?></small>

      </p>

      <p>

      <?php _e(‘Show:’, $this->ID); ?><select name=”sideposts[<?php echo $number; ?>][content]” id=”sideposts-content” class=”widefat”>

      <option value=”posts” <?php selected(‘posts’, $s_show); ?>><?php _e(‘Full Post’, $this->ID); ?></option>

      <option value=”excerpt” <?php selected(‘excerpt’, $s_show); ?>><?php _e(‘Post Excerpt’, $this->ID); ?></option>

      <option value=”ex-thumb” <?php selected(‘ex-thumb’, $s_show); ?>><?php _e(‘Excerpts with thumbnails’, $this->ID); ?></option>

      <option value=”title”<?php selected(‘title’, $s_show); ?>><?php _e(‘Only Post Title’, $this->ID); ?></option>

      </select>

      </p><p>

      <?php _e(‘Thumbnail width:’, $this->ID); ?>

      <input style=”width: 50px;” id=”sideposts-thumbnail” name=”sideposts[<?php echo $number; ?>][thumbnail]” type=”text” value=”<?php echo $s_thumbnail; ?>” />

      <?php _e(‘pixels’, $this->ID)?>

      </p>

      <input type=”hidden” id=”sideposts-submit” name=”sideposts[<?php echo $number; ?>][submit]” value=”true” />

      <?php

      }

      /**

      * Filters the categories not to be shown in main blog area.

      * Also filters private posts from home (and only from home) if there is a widget for private posts.

      *

      * @hook filter ‘pre_get_posts’ on posts query.

      * @param WP_Query &$query By Ref: Prepared query for posts, before doing it.

      * @return void

      */

      function _postsFilter( & $query ) {

      global $wpdb;

      if ( $query->is_category || $query->is_tag || $query->is_day ) {

      return;

      }

      // Some platforms do not process correctly the attachment queries. (Gallery)

      $type = $query->get(‘post_type’);

      if ( ‘attachment’ == $type ) {

      return;

      }

      $options = get_option($this->ID . ‘_widget’);

      $is_front = ( $query->is_home && ( ! $query->get(‘paged’) || 1 == $query->get(‘paged’) ) );

      $cat_in = $query->get(‘category__in’);

      $cat_filter = array();

      if ( is_array($options) && ( $query->is_home || $query->is_feed || $query->is_archive ) ) {

      foreach( $options as $id => $widget ) {

      if ( akv_widget_loaded(“{$this->ID}-{$id}”) ) { // If widget is loaded then apply posts filters.

      $category = (int) $widget[‘category’];

      if ( -99 == $category && ‘private’ != $query->get(‘post_status’) && current_user_can(‘read_private_posts’) && $is_front ) {

      $query->set(‘post__not_in’ , $wpdb->get_col(“SELECT ID FROM {$wpdb->posts} WHERE post_status=’private'”));

      } elseif ( ! in_array($category, $cat_in) ) {

      $cat_filter[] = $category;

      }

      }

      }

      if ( ! empty($cat_filter) ) {

      $query->set(‘category__not_in’, $cat_filter);

      }

      }

      }

      /**

      * Generates the excerpts thumbnails.

      * This is used as a filter for the hook ‘the_excerpt’, added and deleted in the widget function.

      *

      * @uses apply_filters() Calls the ‘ID_thumbnail’ on img tag for the thumbnail.

      * @hook filter ‘the_excerpt’

      * @param string $excerpt The post excerpt.

      * @return string The post excerpt with the attached image tag.

      */

      private function excerptThumbnail( $widget_id ) {

      global $post;

      $settings = get_option($this->ID . ‘_widget’);

      $images = get_children( ‘post_type=attachment&post_mime_type=image&post_parent=’ . $post->ID );

      if ( $images ) {

      $img = array();

      foreach( $images as $imageID => $imagePost ) {

      $img[] = wp_get_attachment_image_src($imageID);

      }

      $thumb = array_pop($img);

      $thumb_h = intval( (int) $settings[$widget_id][‘thumbnail’] * (int) $thumb[2] / (int) $thumb[1] );

      $thumbnail = ‘<img src=”‘. $thumb[0] .'” width=”‘. $settings[$widget_id][‘thumbnail’] .'” height=”‘. $thumb_h .'” class=”alignleft” />’;

      } else {

      $thumbnail = ”;

      }

      return apply_filters($this->ID . ‘_thumbnail’, $thumbnail);

      }

      }

      ?>

      Any help greatly appreciated!

    Removing Archive link and Rss icon:

    You’re going to comment out a range of php code. You open the range by typing a slash and a star. Then you close the range with a star and a slash.

    In the file class.sideposts-widget.php, after line 129, make it look like this:

    /*
    		if ( -99 != (int) $category ) {
    			echo '<li>';
    			echo '<a href="'
    				. get_category_feed_link($category) .'"><img style="border:0;float:right;" src="'
    				. $SidePosts->getURL() . 'rss.png" alt="RSS" /></a>';
    
    			echo '<a href="' . get_category_link($category) .'">';
    			_e('Archive for', $this->pid);
    			echo ' '. $instance['title'] .'</a> &raquo;</li>'; // get_the_category_by_ID($category)
    		}
    */

    If you want to turn the archive code back on just remove the /* and */

    Just take care as the hack is for the current version (2.2.1) but it is applicable if you look for similar lines on the file shown above.

    I’m working on version 3.0 for the plugin. This version will include all widget output in templates that you can modify, edit or create new templates to display the output.

    I have no ETA as I will start my holidays soon and will be on half holidays until September, 15. Hope I can release it before, if not, you will have to wait.

    Hi Txanny,

    I just updated to the latest version of your helpful widget. I had to come back here to figure out how to reapply the hack I posted!

    The location of the code to comment out in version 2.2.2 is the same.

    Txanny thank you for embarking on the update. For now I just changed the CSS to hide the post date and change the appearance of the html output.

    In 2.3 is the same code 😉

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Plugin: SidePosts Widget] How to remove “Archive for X” in SidePosts widget?’ is closed to new replies.