フォーラムへの返信

6件の返信を表示中 - 1 - 6件目 (全6件中)
  • トピック投稿者 mochi-mochi

    (@mochi-mochi)

    jim912様、アドバイスありがとうございます。

    EOFの左側の空白を消したところ、うまく表示されました。

    初心者の質問に回答くださり、感謝しております。

    トピック投稿者 mochi-mochi

    (@mochi-mochi)

    stranger-jp様、ありがとうございます。

    フォーラムのルールを確認できておりませんでした。
    ご迷惑をおかけしてすみません。
    改めてトピックを立てさせていただきます。

    アドバイス、ありがとうございました。

    トピック投稿者 mochi-mochi

    (@mochi-mochi)

    TomoeIntl様、アドバイスありがとうございます。

    仰るとおりに書き直したところ、デバックモードでもエラーの表示が出なくなりました。

    1人では解決できませんでした。

    stranger-jp様も、改めてありがとうございました。

    もうひとつ困っている部分がありますので、お時間がある際に見ていただけませんでしょうか?

    このサイトの記事を参考にして、h2タグの前にアドセンスを差し込むように試したのですが、コピペして記載すると、管理画面が真っ白になってしまいます。何かしらのエラーがあるのだと思いますが、分かりません(汗)

    サイトにある記述を自分のfunctions.phpに書き込んだのが下記の状態です。
    重ね重ねすみませんが、よろしくお願いします。

    <?php
    function load_script(){
    wp_enqueue_script(‘jquery’);
    }
    add_action(‘init’, ‘load_script’);

    //アイキャッチサムネイル
    add_theme_support(‘post-thumbnails’);
    add_image_size(‘thumb100’,100,100,true);
    add_image_size(‘thumb110’,110,110,true);
    add_image_size(‘thumb170’,170,170,true);

    //WordPress の投稿スラッグを自動的に生成する
    function auto_post_slug( $slug, $post_ID, $post_status, $post_type ) {
    if ( preg_match( ‘/(%[0-9a-f]{2})+/’, $slug ) ) {
    $slug = utf8_uri_encode( $post_type ) . ‘-‘ . $post_ID;
    }
    return $slug;
    }
    add_filter( ‘wp_unique_post_slug’, ‘auto_post_slug’, 10, 4 );

    //カスタムメニュー
    register_nav_menus(array(‘navbar’ => ‘ナビゲーションバー’));

    //カスタムヘッダー
    $args = array(
    ‘width’ => 1035,
    ‘height’ => 84,
    ‘flex-height’ => true,
    ‘default-image’ => get_template_directory_uri() . ‘/images/stinger3.png’,
    );
    add_theme_support( ‘custom-header’, $args );

    //RSS
    add_theme_support(‘automatic-feed-links’);

    //エディタスタイル
    add_theme_support(‘editor-style’);
    add_editor_style(‘editor-style.css’);
    function custom_editor_settings( $initArray ){
    $initArray[‘body_class’] = ‘editor-area’;
    return $initArray;
    }
    add_filter( ‘tiny_mce_before_init’, ‘custom_editor_settings’ );

    //画像に重ねる文字の色
    define(‘HEADER_TEXTCOLOR’, ”);

    //画像に重ねる文字を非表示にする
    define(‘NO_HEADER_TEXT’,true);

    //投稿用ファイルを読み込む
    get_template_part(‘functions/create-thread’);

    //カスタム背景
    add_theme_support( ‘custom-background’ );

    //ページャー機能
    function pagination($pages = ”, $range = 4)
    {
    $showitems = ($range * 2)+1;

    global $paged;
    if(empty($paged)) $paged = 1;

    if($pages == ”)
    {
    global $wp_query;
    $pages = $wp_query->max_num_pages;
    if(!$pages)
    {
    $pages = 1;
    }
    }

    if(1 != $pages)
    {
    echo “<div class=\”pagination\”><span>Page “.$paged.” of “.$pages.”</span>”;
    if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo “<a href='”.get_pagenum_link

    (1).”‘>« First”;
    if($paged > 1 && $showitems < $pages) echo “

    Previous“;

    for ($i=1; $i <= $pages; $i++)
    {
    if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems

    ))
    {
    echo ($paged == $i)? “<span class=\”current\”>”.$i.”</span>”:”<a href='”.get_pagenum_link

    ($i).”‘ class=\”inactive\”>”.$i.””;
    }
    }

    if ($paged < $pages && $showitems < $pages) echo “<a href=\””.get_pagenum_link($paged +

    1).”\”>Next ›”;
    if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo “<a

    href='”.get_pagenum_link($pages).”‘>Last »”;
    echo “</div>\n”;
    }
    }

    //ヘッダーを綺麗に
    remove_action( ‘wp_head’, ‘feed_links_extra’, 3 );
    remove_action( ‘wp_head’, ‘feed_links’, 2 );
    remove_action( ‘wp_head’, ‘rsd_link’ );
    remove_action( ‘wp_head’, ‘wlwmanifest_link’ );
    remove_action( ‘wp_head’, ‘index_rel_link’ );
    remove_action( ‘wp_head’, ‘parent_post_rel_link’, 10, 0 );
    remove_action( ‘wp_head’, ‘start_post_rel_link’, 10, 0 );
    remove_action( ‘wp_head’, ‘adjacent_posts_rel_link_wp_head’, 10, 0 );
    remove_action( ‘wp_head’, ‘wp_generator’ );

    //moreリンク
    function custom_content_more_link( $output ) {
    $output = preg_replace(‘/#more-[\d]+/i’, ”, $output );
    return $output;
    }
    add_filter( ‘the_content_more_link’, ‘custom_content_more_link’ );

    //セルフピンバック禁止
    function no_self_ping( &$links ) {
    $home = home_url();
    foreach ( $links as $l => $link )
    if ( 0 === strpos( $link, $home ) )
    unset($links[$l]);
    }
    add_action( ‘pre_ping’, ‘no_self_ping’ );

    //ウイジェット追加
    if ( !function_exists(‘dynamic_sidebar’) || !dynamic_sidebar(4) )
    register_sidebars(1,
    array(
    ‘name’=>’サイドバー1’,
    ‘before_widget’ => ‘

    • ‘,
      ‘after_widget’ => ‘

    ‘,
    ‘before_title’ => ‘<h4 class=”menu_underh2″>’,
    ‘after_title’ => ‘</h4>’,
    ));
    register_sidebars(1,
    array(
    ‘name’=>’スクロール広告用’,
    ‘before_widget’ => ‘

    • ‘,
      ‘after_widget’ => ‘

    ‘,
    ‘before_title’ => ‘<h4 class=”menu_underh2″ style=”text-align:left;”>’,
    ‘after_title’ => ‘</h4>’,
    ));
    register_sidebars(1,
    array(
    ‘name’=>’Googleアドセンス用’,
    ‘before_widget’ => ”,
    ‘after_widget’ => ”,
    ‘before_title’ => ‘<h4 style=”display:none”>’,
    ‘after_title’ => ‘</h4>’,
    ));

    register_sidebars(1,
    array(
    ‘name’=>’Googleアドセンスのスマホ用width300’,
    ‘before_widget’ => ”,
    ‘after_widget’ => ”,
    ‘before_title’ => ‘<h4 style=”display:none”>’,
    ‘after_title’ => ‘</h4>’,
    ));

    //contents widthの指定
    if ( ! isset( $content_width ) ) $content_width = 620;

    //更新日の追加
    function get_mtime($format) {
    $mtime = get_the_modified_time(‘Ymd’);
    $ptime = get_the_time(‘Ymd’);
    if ($ptime > $mtime) {
    return get_the_time($format);
    } elseif ($ptime === $mtime) {
    return null;
    } else {
    return get_the_modified_time($format);
    }
    }

    //ショートコードを外す
    function stinger_noshotcode( $content ) {
    if ( ! preg_match( ‘/\[.+?\]/’, $content, $matches ) ) {
    return $content;
    }

    $content = str_replace( $matches[0], ”, $content );

    return $content;
    }

    //スマホ表示分岐
    function is_mobile(){
    $useragents = array(
    ‘iPhone’, // iPhone
    ‘iPod’, // iPod touch
    ‘Android.*Mobile’, // 1.5+ Android *** Only mobile
    ‘Windows.*Phone’, // *** Windows Phone
    ‘dream’, // Pre 1.5 Android
    ‘CUPCAKE’, // 1.5+ Android
    ‘blackberry9500’, // Storm
    ‘blackberry9530’, // Storm
    ‘blackberry9520’, // Storm v2
    ‘blackberry9550’, // Storm v2
    ‘blackberry9800’, // Torch
    ‘webOS’, // Palm Pre Experimental
    ‘incognito’, // Other iPhone browser
    ‘webmate’ // Other iPhone browser

    );
    $pattern = ‘/’.implode(‘|’, $useragents).’/i’;
    return preg_match($pattern, $_SERVER[‘HTTP_USER_AGENT’]);
    }

    function add_ads_before_1st_h2($the_content) {
    if (is_single()) {
    if (wp_is_mobile()) {
    $ads = <<< EOF
    ★レクタングル中のコードを記述
    EOF;
    } else {
    $ads = <<< EOF
    ★レクタングル大のコードを記述
    EOF;
    }
    $h2 = ‘/<h2.*?>/i’;//H2見出しのパターン
    if ( preg_match( $h2, $the_content, $h2s )) {//H2見出しが本文中にあるかどうか
    $the_content = preg_replace($h2, $ads.$h2s[0], $the_content, 1);//最初のH2を置換
    }
    }
    return $the_content;
    }
    add_filter(‘the_content’,’add_ads_before_1st_h2′);

    ?>

    トピック投稿者 mochi-mochi

    (@mochi-mochi)

    stranger-jp様、ありがとうございます。

    すみません。勘違いでしたか(汗)

    home内はこのような記述をしております。
    ご指摘のとおり、loop_countは後から付け加えたものです。

    お気づきの点があれば、ご教示ください。
    よろしくお願いします。

    <?php get_header(); ?>

    <div class=”post kizi”>

    <!–ループ開始–>
    <div id=”dendo”> </div>
    <!– /#dendo –>

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post();$loop_count++; ?>
    <?php if ( $loop_count == 2 || $loop_count == 5 || $loop_count == 8 ) : ?>

    <?php if (wp_is_mobile()): ?>
    アドセンスコード

    <?php else: ?>
    アドセンスコード

    <?php endif; ?>
    <?php endif; ?>
    <div class=”entry”>

    <div class=”sumbox”> ” title=”<?php the_title_attribute(); ?>”>
    <?php if ( has_post_thumbnail() ): // サムネイルを持っているときの処理 ?>
    <?php
    $title= get_the_title();
    the_post_thumbnail(‘thumb170’,
    array( ‘alt’ =>$title, ‘title’ => $title)); ?>
    <?php else: // サムネイルを持っていないときの処理 ?>
    <img src=”<?php echo get_template_directory_uri(); ?>/images/no-img.png” alt=”no image” title=”no image” width=”170″ height=”170″ />
    <?php endif; ?>
    </div>
    <!– /.sumbox –>

    <div class=”entry-content”>
    <h3 class=”entry-title-ac”> ” title=”<?php the_title_attribute(); ?>”>
    <?php the_title(); ?>
    </h3>
    <div class=”blog_info contentsbox”>
    <p>
    <?php the_time(‘Y/m/d’) ?>
    |
    <?php the_category(‘, ‘) ?>
    <?php the_tags(”, ‘, ‘); ?>
    </p>
    </div>
    <p class=”dami”><?php echo mb_substr(strip_tags($post-> post_content),0,30).’…’; ?></p>
    <div style=”float:right;”><p class=”motto”>“>続きを見る</p></div>

    </div>
    <!– .entry-content –>

    <div class=”clear”></div>
    </div>
    <!–/entry–>

    <?php endwhile; else: ?>
    <p>記事がありません</p>
    <?php endif; ?>

    <!–ページナビ–>

    <?php if (function_exists(“pagination”)) {
    pagination($wp_query->max_num_pages);
    } ?>
    <!–ループ終了–>
    </div>
    <!– END div.post –>
    <?php get_footer(); ?>

    トピック投稿者 mochi-mochi

    (@mochi-mochi)

    stranger-jp様、ありがとうございます。

    ご指摘のとおり、WP Minifyというプラグインを使用しておりました。

    さっそく、これを削除し、WP Super Cacheを追加してみました。

    もう一度、デバックをtrueにしてみますと、今度は、トップページの記事リストの上部に以下のメッセージが出ました。

    Notice: Undefined variable: loop_count in /home/ドメイン名/ドメイン名.com/public_html/wp-content/themes/stinger3ver20131217/home.php on line 9

    先ほどのNoticeも今回のNoticeもプラグインと干渉するためでしょうか?

    動作は問題無いので、falseに戻し、そのまま使ってみようと思います。

    トピック投稿者 mochi-mochi

    (@mochi-mochi)

    初心者で、質問も要領をえず、申し訳ありません。

    いろいろいじっているうちに、デバックモード(true)になり、上記のメッセージが出ていたようです。

    全体では以下のようなメッセージでした。
    現時点でこれ以外にメッセージは出ていません。

    Notice: is_feed was called incorrectly. Conditional query tags do not work before the query is run. Before then, they always return false. Please see Debugging in WordPress for more information. (This message was added in version 3.1.) in /home/ドメイン/ドメイン.com/public_html/wp-includes/functions.php on line 3245

    これは、functions.phpに未だ問題が残っているということでしょうか?

    functions.phpをいじって真っ白になり、それを修復する経過中に、category orderというプラグインにエラーが出たり、スクロールすると追尾するスペースが消えてしまったり、管理画面の上部にエラーメッセージが出る状態などになりましたが、今はそれらは正常です。

    デバックをfalseに戻すと、エラーメッセージは消え、見た目は問題なくブログが表示されるようになりますが、このままで良いのでしょうか?

    よろしくお願いします。

6件の返信を表示中 - 1 - 6件目 (全6件中)