• 以下のソースの必要性が今いち感じられません。
    削除したところで、ビジュアル的な不具合はありません。
    このソースを削除すると、SEO対策上、ソースが短くなるというメリットはありますが、
    削除してしまうと影響の出るデメリットがございましたら、ご教授ください。

    <script type=”text/javascript” language=”javascript”>
    <?php
    $i_post = 1;
    while ($i_post <= 20) {
    ?>
    function AnyHeight_<?php echo $i_post ?>()
    {
    var top_<?php echo $i_post ?>=document.getElementById(“top_level_<?php echo $i_post ?>”).offsetTop;
    var bottom_<?php echo $i_post ?>=document.getElementById(“bottom_level_<?php echo $i_post ?>”).offsetTop;
    var height_<?php echo $i_post ?>=bottom_<?php echo $i_post ?>-top_<?php echo $i_post ?>;
    document.getElementById(“column1_<?php echo $i_post ?>”).style.height=height_<?php echo $i_post ?>+’px’;
    document.getElementById(“column2_<?php echo $i_post ?>”).style.height=height_<?php echo $i_post ?>+’px’;
    }
    <?php
    $onload .= ‘AnyHeight_’ . $i_post . ‘(); ‘;
    $i_post++;
    }
    ?>
    </script>

    ↑↑↑↑↑
    これを削除すると、以下が削除されます。

    <script type=”text/javascript” language=”javascript”>
    function AnyHeight_1()
    {
    var top_1=document.getElementById(“top_level_1”).offsetTop;
    var bottom_1=document.getElementById(“bottom_level_1”).offsetTop;
    var height_1=bottom_1-top_1;
    document.getElementById(“column1_1”).style.height=height_1+’px’;
    document.getElementById(“column2_1”).style.height=height_1+’px’;
    }
    function AnyHeight_2()
    {
    var top_2=document.getElementById(“top_level_2”).offsetTop;
    var bottom_2=document.getElementById(“bottom_level_2”).offsetTop;
    var height_2=bottom_2-top_2;
    document.getElementById(“column1_2”).style.height=height_2+’px’;
    document.getElementById(“column2_2”).style.height=height_2+’px’;
    }
    function AnyHeight_3()
    {
    var top_3=document.getElementById(“top_level_3”).offsetTop;
    var bottom_3=document.getElementById(“bottom_level_3”).offsetTop;
    var height_3=bottom_3-top_3;
    document.getElementById(“column1_3”).style.height=height_3+’px’;
    document.getElementById(“column2_3”).style.height=height_3+’px’;
    }
    function AnyHeight_4()
    {
    var top_4=document.getElementById(“top_level_4”).offsetTop;
    var bottom_4=document.getElementById(“bottom_level_4”).offsetTop;
    var height_4=bottom_4-top_4;
    document.getElementById(“column1_4”).style.height=height_4+’px’;
    document.getElementById(“column2_4”).style.height=height_4+’px’;
    }
    function AnyHeight_5()
    {
    var top_5=document.getElementById(“top_level_5”).offsetTop;
    var bottom_5=document.getElementById(“bottom_level_5”).offsetTop;
    var height_5=bottom_5-top_5;
    document.getElementById(“column1_5”).style.height=height_5+’px’;
    document.getElementById(“column2_5”).style.height=height_5+’px’;
    }
    function AnyHeight_6()
    {
    var top_6=document.getElementById(“top_level_6”).offsetTop;
    var bottom_6=document.getElementById(“bottom_level_6”).offsetTop;
    var height_6=bottom_6-top_6;
    document.getElementById(“column1_6”).style.height=height_6+’px’;
    document.getElementById(“column2_6”).style.height=height_6+’px’;
    }
    function AnyHeight_7()
    {
    var top_7=document.getElementById(“top_level_7”).offsetTop;
    var bottom_7=document.getElementById(“bottom_level_7”).offsetTop;
    var height_7=bottom_7-top_7;
    document.getElementById(“column1_7”).style.height=height_7+’px’;
    document.getElementById(“column2_7”).style.height=height_7+’px’;
    }
    function AnyHeight_8()
    {
    var top_8=document.getElementById(“top_level_8”).offsetTop;
    var bottom_8=document.getElementById(“bottom_level_8”).offsetTop;
    var height_8=bottom_8-top_8;
    document.getElementById(“column1_8”).style.height=height_8+’px’;
    document.getElementById(“column2_8”).style.height=height_8+’px’;
    }
    function AnyHeight_9()
    {
    var top_9=document.getElementById(“top_level_9”).offsetTop;
    var bottom_9=document.getElementById(“bottom_level_9”).offsetTop;
    var height_9=bottom_9-top_9;
    document.getElementById(“column1_9”).style.height=height_9+’px’;
    document.getElementById(“column2_9”).style.height=height_9+’px’;
    }
    function AnyHeight_10()
    {
    var top_10=document.getElementById(“top_level_10”).offsetTop;
    var bottom_10=document.getElementById(“bottom_level_10”).offsetTop;
    var height_10=bottom_10-top_10;
    document.getElementById(“column1_10”).style.height=height_10+’px’;
    document.getElementById(“column2_10”).style.height=height_10+’px’;
    }
    function AnyHeight_11()
    {
    var top_11=document.getElementById(“top_level_11”).offsetTop;
    var bottom_11=document.getElementById(“bottom_level_11”).offsetTop;
    var height_11=bottom_11-top_11;
    document.getElementById(“column1_11”).style.height=height_11+’px’;
    document.getElementById(“column2_11”).style.height=height_11+’px’;
    }
    function AnyHeight_12()
    {
    var top_12=document.getElementById(“top_level_12”).offsetTop;
    var bottom_12=document.getElementById(“bottom_level_12”).offsetTop;
    var height_12=bottom_12-top_12;
    document.getElementById(“column1_12”).style.height=height_12+’px’;
    document.getElementById(“column2_12”).style.height=height_12+’px’;
    }
    function AnyHeight_13()
    {
    var top_13=document.getElementById(“top_level_13”).offsetTop;
    var bottom_13=document.getElementById(“bottom_level_13”).offsetTop;
    var height_13=bottom_13-top_13;
    document.getElementById(“column1_13”).style.height=height_13+’px’;
    document.getElementById(“column2_13”).style.height=height_13+’px’;
    }
    function AnyHeight_14()
    {
    var top_14=document.getElementById(“top_level_14”).offsetTop;
    var bottom_14=document.getElementById(“bottom_level_14”).offsetTop;
    var height_14=bottom_14-top_14;
    document.getElementById(“column1_14”).style.height=height_14+’px’;
    document.getElementById(“column2_14”).style.height=height_14+’px’;
    }
    function AnyHeight_15()
    {
    var top_15=document.getElementById(“top_level_15”).offsetTop;
    var bottom_15=document.getElementById(“bottom_level_15”).offsetTop;
    var height_15=bottom_15-top_15;
    document.getElementById(“column1_15”).style.height=height_15+’px’;
    document.getElementById(“column2_15”).style.height=height_15+’px’;
    }
    function AnyHeight_16()
    {
    var top_16=document.getElementById(“top_level_16”).offsetTop;
    var bottom_16=document.getElementById(“bottom_level_16”).offsetTop;
    var height_16=bottom_16-top_16;
    document.getElementById(“column1_16”).style.height=height_16+’px’;
    document.getElementById(“column2_16”).style.height=height_16+’px’;
    }
    function AnyHeight_17()
    {
    var top_17=document.getElementById(“top_level_17”).offsetTop;
    var bottom_17=document.getElementById(“bottom_level_17”).offsetTop;
    var height_17=bottom_17-top_17;
    document.getElementById(“column1_17”).style.height=height_17+’px’;
    document.getElementById(“column2_17”).style.height=height_17+’px’;
    }
    function AnyHeight_18()
    {
    var top_18=document.getElementById(“top_level_18”).offsetTop;
    var bottom_18=document.getElementById(“bottom_level_18”).offsetTop;
    var height_18=bottom_18-top_18;
    document.getElementById(“column1_18”).style.height=height_18+’px’;
    document.getElementById(“column2_18”).style.height=height_18+’px’;
    }
    function AnyHeight_19()
    {
    var top_19=document.getElementById(“top_level_19”).offsetTop;
    var bottom_19=document.getElementById(“bottom_level_19”).offsetTop;
    var height_19=bottom_19-top_19;
    document.getElementById(“column1_19”).style.height=height_19+’px’;
    document.getElementById(“column2_19”).style.height=height_19+’px’;
    }
    function AnyHeight_20()
    {
    var top_20=document.getElementById(“top_level_20”).offsetTop;
    var bottom_20=document.getElementById(“bottom_level_20”).offsetTop;
    var height_20=bottom_20-top_20;
    document.getElementById(“column1_20”).style.height=height_20+’px’;
    document.getElementById(“column2_20”).style.height=height_20+’px’;
    }
    </script>

3件の返信を表示中 - 1 - 3件目 (全3件中)
  • サイトの元のソースが見れないので半分憶測ですが、AnyHeightというくらいですので好きなサイズの高さにできる?ということでしょうか。
    これがjavascriptで記述されているということは、ページを表示している状態でそのページを見ているユーザがドラッグでサイズ変更可?なのですかねぇ。

    ソースを表示してみて記事などのタグにclass=”column1_1″とかの指定は見当たりませんか?
    まったくないとすれば、本来例えばカテゴリ名にcolumn1とか指定することになっているとか(以前にカテゴリを特定のカテゴリ名にしないとまともに動かないテーマがありましたねぇ)いろいろ考えられますが・・・見当違いでしたらすみません。

    トピック投稿者 hi-roki

    (@hi-roki)

    shokun0803 様

    コメントありがとうございます。
    元のサイトは
    http://eventgakuen.com です。

    憶測での見解、恐縮です。
    ●そのページを見ているユーザがドラッグでサイズ変更可?なのですかねぇ。
    このような感じではないです。
    ●class=”column1_1
    現在は、表示設定項目で、「固定ページ」を指定しております。
    ですが、指定しているトップページのソースにはご推察通り

    <div id=”column1_<?php echo $i_post2; ?>” class=”left”>
    <div id=”column2_<?php echo $i_post2; ?>” class=”right date”>

    といったような記載があります。

    ですが、活かされていないような気もします。

    <?php
    /*
    Template Name: インフォ
    */
    ?> <?php get_header(); ?>
    <?php get_sidebar(); ?>
    <div id=”content” class=”column”>
    <div class=”indent”>
    <?php
    $i_post2 = 0;
    ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?><div class=”article”>
    <?php
    $i_post2++;
    ?>
    <!–block –>
    <!–title –>
    <div class=”title”>
    <div id=”top_level_<?php echo $i_post2; ?>”></div>
    <div id=”column1_<?php echo $i_post2; ?>” class=”left”>
    <div class=”t”>
    <div class=”l”>
    <div class=”r”>
    <div class=”l_t”>
    <div class=”r_t”>
    <div class=”indent”>
    <h4><?php the_title(); ?></h4>
    </div>
    </div>
    </div>
    </div>
    </div>
    </div>
    </div>
    <div id=”column2_<?php echo $i_post2; ?>” class=”right date”>
    <div class=”t”>
    <div class=”l”>
    <div class=”r”>
    <div class=”l_t”>
    <div class=”r_t”>
    <div class=”indent”>

    </div>
    </div>
    </div>
    </div>
    </div>
    </div>
    </div>
    <div class=”clear”></div>
    <div id=”bottom_level_<?php echo $i_post2; ?>”></div>
    </div>
    <!–title end–>
    <!–content text –>
    <div class=”content_text”>
    <div class=”t”>
    <div class=”b”>
    <div class=”l”>
    <div class=”r”>
    <div class=”l_t”>
    <div class=”l_b”>
    <div class=”r_t”>
    <div class=”r_b”>
    <div class=”indent”>
    <?php the_content(‘<p class=”serif”>Read the rest of this entry »</p>’); ?>
    <?php link_pages(‘<p>Pages: ‘, ‘</p>’, ‘number’); ?>
    <div class=”navigation”>
    <div class=”left”><?php previous_post_link(‘« %link’) ?></div>
    <div class=”right”><?php next_post_link(‘%link »’) ?></div>
    <div class=”clear”></div>
    </div>
    <div class=”post” id=”post-<?php the_ID(); ?>”>
    <p class=”postmetadataalt”>
    </p>
    </div>
    </div>
    </div>
    </div>
    </div>
    </div>
    </div>
    </div>
    </div>
    </div>
    </div>
    <!–content text end–>
    <!–block end–>

    </div>
    <br style=”clear:both;” />
    <?php endwhile; else: ?>
    <p>Sorry, no posts matched your criteria.</p>
    <?php endif; ?>
    </div>
    </div>
    <?php get_footer(); ?>

    またもや憶測で失礼します(汗)

    offsetTopはエレメントの位置を取得します。それをheightにpxで置き換えているのでcssで実現しているタイトル部分(ホームでいうところのトップページの文字部分)のオレンジ枠とその横の白枠の縦のラインの長さを調節しているのではないでしょうか。
    今のように1行だけのタイトル文字だと長さが変わることはありませんが、タイトル文字などが長くなって改行が入った場合(そもそも折り返しされるのかな?)縦に伸びるラインがcssでの指定だけだと足りなくなって切れてしまうのではないでしょうか?
    そこでvar height_1=bottom_1-top_1で高さを割り出しstyle.height=height_1+’px’でstyleを修正しているのではないかと思います。

    現にJavascriptを無効にすると白枠の縦線が消えます(関係ないかな?)

    憶測ばかりですみません・・・

3件の返信を表示中 - 1 - 3件目 (全3件中)
  • トピック「function AnyHeight_<?php echo $i_post ?>()」には新たに返信することはできません。