サポート » 使い方全般 » サイドバーの高さを設定したい

  • 解決済 hirotani

    (@hirotani)


    WordPress初心者です。
    使っているテーマは、[my base 0.5]です。
    サイドバーにアーカイブや最近の投稿が表示されています。
    [最近の投稿]が増えてきたので、ウィジェットから[blue-sidebar]/[最近の投稿]で[表示する投稿数]を80にしましたがあふれています。
    この方法は限界なので、高さ[height]を指定したスタイルを定義しておいて、[最近の投稿]の表示部分で、
    style="overflow:auto"
    にしたいのですが、どの部分を修正すればいいかわかりません。
    どなたかご教示いただけませんでしょうか。

8件の返信を表示中 - 1 - 8件目 (全8件中)
  • こんにちは
    テーマは以下のものですか
    http://wordpress.org/extend/themes/my-base

    ですか

    ソースが以下のようになれば、いいと思いますが、スクロールがブラウザによって、縦横に発生するかもしれません

    <div class="sidebar sidebar-left big-sidebar" style="height:好きな値px;overflow:auto;">

    場所は、sidebar-left.phpまたは、sidebar-right.php
    に(sidebar-left.phpの場合)

    if( $sidebars[ count($sidebars) - 1 ] != 'l' ){
    		print "<div class=\"sidebar sidebar-left ".$class_left_sidebar."\">\n";//この行を修正すればいいです。
    		if( strlen( $sb -> getMySidebar('red-sidebar') ) > 0 ){
    			print $sb -> getMySidebar('red-sidebar');
    		}

    インラインスタイルを使わないなら、

    style.cssの以下の部分を修正すればいいと思います。

    試してはいないので、やってみてください

    /* sidebar defines */
    
    div.sidebar.big-sidebar { width:350px; min-height:450px; padding:10px 5px 35px 5px; float:left;   background:#ffffff; background-image:url('resources/images/bkg-big-sidebar.png'); background-repeat:no-repeat; }
    div.sidebar.small-sidebar { width:170px; min-height:450px; padding:10px 5px 35px 5px; float:left;  background:#ffffff; background-image:url('resources/images/bkg-small-sidebar.png'); background-repeat:no-repeat; }

    トピック投稿者 hirotani

    (@hirotani)

    nobitaさん

    早速のご教示ありがとうございます。
    私の説明が悪かったと思います。
    申し訳ありません。
    サイドバー全体ではなく、[最近の投稿]あるいは[アーカイブ]だけ高さ設定したいのです。
    もしお分かりになりましたら、よろしくお願いします。

    /hirotani

    私の説明が悪かったと思います。

    私の理解力がないだけです。

    お詫びに、汚いコードですが
    どうか、きれいにして使ってください。
    したのコードを、functions.phpに貼り付けて、ウィジェットの画面から、
    Recent Meny Posts ウィジェットを呼び出してください:)

    <?php
    
    add_action('widgets_init', create_function('', 'return register_widget("my_widget_recent_posts");'));
    /**
     * my_widget_recent_posts class
     *
     */
    class my_widget_recent_posts extends WP_Widget {
    
    	function __construct() {
    		$widget_ops = array('classname' => 'my_widget_recent_entries', 'description' => __( "The Meny recent posts on your site") );
    		parent::__construct('my-recent-posts', __('Recent Meny Posts'), $widget_ops);
    		$this->alt_option_name = 'my_widget_recent_entries';
    
    		add_action( 'save_post', array(&$this, 'flush_widget_cache') );
    		add_action( 'deleted_post', array(&$this, 'flush_widget_cache') );
    		add_action( 'switch_theme', array(&$this, 'flush_widget_cache') );
    	}
    
    	function widget($args, $instance) {
    		$cache = wp_cache_get('my_widget_recent_posts', 'widget');
    
    		if ( !is_array($cache) )
    			$cache = array();
    
    		if ( ! isset( $args['widget_id'] ) )
    			$args['widget_id'] = $this->id;
    
    		if ( isset( $cache[ $args['widget_id'] ] ) ) {
    			echo $cache[ $args['widget_id'] ];
    			return;
    		}
    
    		$default_args = array(  'before_widget' => '<div style="height:200px;overflow:auto;">','after_widget'=> '</div>' );
    		array_merge($default_args,$args);
    
    		ob_start();
    		extract($args);
    
    		$title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Posts') : $instance['title'], $instance, $this->id_base);
    		if ( empty( $instance['number'] ) || ! $number = absint( $instance['number'] ) )
     			$number = 10;
    
    		$r = new WP_Query( apply_filters( 'widget_posts_args', array( 'posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true ) ) );
    		if ($r->have_posts()) :
    ?>
    		<?php echo $before_widget; ?>
    		<?php if ( $title ) echo $before_title . $title . $after_title; ?>
    		<ul>
    		<?php  while ($r->have_posts()) : $r->the_post(); ?>
    		<li><a href="<?php the_permalink() ?>" title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?></a></li>
    		<?php endwhile; ?>
    		</ul>
    		<?php echo $after_widget; ?>
    <?php
    		// Reset the global $the_post as this query will have stomped on it
    		wp_reset_postdata();
    
    		endif;
    
    		$cache[$args['widget_id']] = ob_get_flush();
    		wp_cache_set('my_widget_recent_posts', $cache, 'widget');
    	}
    
    	function update( $new_instance, $old_instance ) {
    		$instance = $old_instance;
    		$instance['title'] = strip_tags($new_instance['title']);
    		$instance['number'] = (int) $new_instance['number'];
    		$this->flush_widget_cache();
    
    		$alloptions = wp_cache_get( 'alloptions', 'options' );
    		if ( isset($alloptions['my_widget_recent_entries']) )
    			delete_option('my_widget_recent_entries');
    
    		return $instance;
    	}
    
    	function flush_widget_cache() {
    		wp_cache_delete('my_widget_recent_posts', 'widget');
    	}
    
    	function form( $instance ) {
    		$title = isset($instance['title']) ? esc_attr($instance['title']) : '';
    		$number = isset($instance['number']) ? absint($instance['number']) : 80;
    ?>
    		<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></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('number'); ?>"><?php _e('Number of posts to show:'); ?></label>
    		<input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo $number; ?>" size="3" /></p>
    <?php
    	}
    }
    ?>

    朝見たら、動いてなかったので、すみません

    <?php
    
    add_action('widgets_init', create_function('', 'return register_widget("my_widget_recent_posts");'));
    /**
     * my_widget_recent_posts class
     *
     */
    class my_widget_recent_posts extends WP_Widget {
    
    	function __construct() {
    		$widget_ops = array('classname' => 'my_widget_recent_entries', 'description' => __( "The Meny recent posts on your site") );
    		parent::__construct('my-recent-posts', __('Recent Meny Posts'), $widget_ops);
    		$this->alt_option_name = 'my_widget_recent_entries';
    
    		add_action( 'save_post', array(&$this, 'flush_widget_cache') );
    		add_action( 'deleted_post', array(&$this, 'flush_widget_cache') );
    		add_action( 'switch_theme', array(&$this, 'flush_widget_cache') );
    	}
    
    	function widget($args, $instance) {
    		$cache = wp_cache_get('my_widget_recent_posts', 'widget');
    
    		if ( !is_array($cache) )
    			$cache = array();
    
    		if ( ! isset( $args['widget_id'] ) )
    			$args['widget_id'] = $this->id;
    
    		if ( isset( $cache[ $args['widget_id'] ] ) ) {
    			echo $cache[ $args['widget_id'] ];
    			return;
    		}
    
    		$args = array(  'before_widget' => '<div style="height:200px;overflow:auto;">','after_widget'=> '</div>' );
    
    		ob_start();
    		extract($args);
    
    		$title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Posts') : $instance['title'], $instance, $this->id_base);
    		if ( empty( $instance['number'] ) || ! $number = absint( $instance['number'] ) )
     			$number = 10;
    
    		$r = new WP_Query( apply_filters( 'widget_posts_args', array( 'posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true ) ) );
    		if ($r->have_posts()) :
    ?>
    		<?php echo $before_widget; ?>
    		<?php if ( $title ) echo $before_title . $title . $after_title; ?>
    		<ul>
    		<?php  while ($r->have_posts()) : $r->the_post(); ?>
    		<li><a href="<?php the_permalink() ?>" title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?></a></li>
    		<?php endwhile; ?>
    		</ul>
    		<?php echo $after_widget; ?>
    <?php
    		// Reset the global $the_post as this query will have stomped on it
    		wp_reset_postdata();
    
    		endif;
    
    		$cache[$args['widget_id']] = ob_get_flush();
    		wp_cache_set('my_widget_recent_posts', $cache, 'widget');
    	}
    
    	function update( $new_instance, $old_instance ) {
    		$instance = $old_instance;
    		$instance['title'] = strip_tags($new_instance['title']);
    		$instance['number'] = (int) $new_instance['number'];
    		$this->flush_widget_cache();
    
    		$alloptions = wp_cache_get( 'alloptions', 'options' );
    		if ( isset($alloptions['my_widget_recent_entries']) )
    			delete_option('my_widget_recent_entries');
    
    		return $instance;
    	}
    
    	function flush_widget_cache() {
    		wp_cache_delete('my_widget_recent_posts', 'widget');
    	}
    
    	function form( $instance ) {
    		$title = isset($instance['title']) ? esc_attr($instance['title']) : '';
    		$number = isset($instance['number']) ? absint($instance['number']) : 80;
    ?>
    		<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></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('number'); ?>"><?php _e('Number of posts to show:'); ?></label>
    		<input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo $number; ?>" size="3" /></p>
    <?php
    	}
    }
    ?>
    トピック投稿者 hirotani

    (@hirotani)

    nobitaさん

    プログラムを送ってくださりありがとうございます。

    私はWordPressのユーザですが、プログラムの仕組みは知りません。
    教えていただきましたが、どこをどうしたらいいかわかりません。
    この際少し勉強したいと思います。

    ところが申し訳ないのですが、向こう1週間この件に時間を割けません。
    来週になったら取組たいと思います。
    大変ありがとうございました。

    /hirotani

    トピック投稿者 hirotani

    (@hirotani)

    nobitaさん

    お世話になります。
    分からないままに、[my base]の[style.css]に

    .widget.widget_recent_entries {width:200px; height:500px; margin: 0px 0px 20px 0px; overflow:auto}

    を挿入しましたら、希望の状態になりました。
    もしかしたら乱暴で副作用があるのかもしれません。

    どちらにしても、来週以降nobitaさんのプログラムを勉強させていただきたいと思います。

    また、上記のCSSの修正について、ご意見があればお聞かせください。

    /hirotani

    すばらしいです

    私の回答は、愚の骨頂! 忘れていただいていいです。

    よい答えを出していただきました とてもうれしい気分です

    トピック投稿者 hirotani

    (@hirotani)

    nobitaさん

    色々ありがとうございました。

    /hirotani

8件の返信を表示中 - 1 - 8件目 (全8件中)
  • トピック「サイドバーの高さを設定したい」には新たに返信することはできません。