メインコンテンツへ移動

Search results of "snow_monkey_template_part_render"

15件の結果を表示中 - 1 - 15件目 (全254件中)
  • 投稿者
    検索結果
  • アバター画像キタジマ タカシ
    参加者
    2619

    ## 既存のテンプレートを希望のレイアウトになるようにカスタマイズする

    snow-monkey/template-parts/content/entry/entry.php の出力をカスタマイズする例です。記事の本文部分のみカスタマイズしたい場合は、snow-monkey/template-parts/content/entry/content/content.php を対象に変更してください。

    add_filter(
    	'snow_monkey_template_part_render_template-parts/content/entry/entry',
    	function ( $html, $name ) {
    		// 投稿タイプが「投稿」のときのみ。
    		if ( 'post' === $name ) {
    			ob_start();
    			?>
    <article <?php post_class(); ?>>
    	<div class="xxx">
    		<div class="xxx">
    			<?php the_post_thumbnail(); ?>
    		</div>
    
    		<div class="xxx">
    			<div class="xxx">
    				<?php the_date(); ?> | <?php the_category(); ?>
    			</div>
    
    			<div class="xxx">
    				<?php the_content(); ?>
    			</div>
    		</div>
    	</div>
    </article>
    			<?php
    			return ob_get_clean();
    		}
    		return $html;
    	},
    	10,
    	2
    );
    1
    Who liked:
    #145600

    返信が含まれるトピック: footerのカスタマイズについて

    アバター画像キタジマ タカシ
    参加者
    2619

    Snow Monkey が用意しているフッターの種類にはこういうレイアウトは無いので、コーディングしちゃうのが速くて確実かなと思います。

    add_filter(
    	'snow_monkey_template_part_render_footer',
    	function( $html ) {
    		return 'ここに HTML';
    	}
    );
    0
    Who liked: No user
    アバター画像キタジマ タカシ
    参加者
    2619

    あ、フック名が変ですね。

    snow_monkey_template_part_render_template-parts/loop/entry-summary/
    

    snow_monkey_template_part_render_template-parts/loop/entry-summary
    
    1
    Who liked:
    アバター画像キタジマ タカシ
    参加者
    2619

    has_category( 'demae', $post ) となっていますが $post が存在しないためエラーがでちゃうのではないかなと思います。global $post を入れて、グローバル変数の $post を参照するとどうでしょうか?

    add_filter(
    	'snow_monkey_template_part_render_template-parts/loop/entry-summary/',
    	function( $html ) {
    		global $post;
    
    		if ( has_category( 'demae', $post ) ) {
    			$html = str_replace(
    				'<a',
    				'<a target="_blank" rel="noreferrer noopener"',
    				$html
    			);
    		}
    		return $html;
    	}
    );
    1
    Who liked:
    林淳一
    参加者
    29

    キタジマ様

    ご確認いただきありがとうございます。

    やりたいことは、 「任意のタクソノミーの投稿」ブロックでカテゴリーが「demae」の場合、 新規ウィンドウで開きたいです。

    下記コードをmy-snow-monkey.phpに追加しましたが、 新規ウィンドウでは開きませんでした。

    add_filter(
    	'snow_monkey_template_part_render_template-parts/loop/entry-summary/',
    	function( $html ) {
    		if ( has_category( 'demae', $post ) ) {
    			$html = str_replace(
    				'<a',
    				'<a target="_blank" rel="noreferrer noopener"',
    				$html
    			);
    		}
    		return $html;
    	}
    );
    0
    Who liked: No user
    アバター画像キタジマ タカシ
    参加者
    2619

    もし「記事に飛ぶリンクを新規ウィンドウで開きたい」であれば、snow_monkey_template_part_render_template-parts/loop/entry-summary フックによるカスタマイズで大丈夫なはずです。

    ただし、

    if ( is_category( 'demae' ) || is_category( 'information' ) ) {
    

    が問題になると思います。これは今「demae カテゴリーアーカイブページを表示している」か「information カテゴリーアーカイブページを表示している」場合にのみ実行されるので、任意のタクソノミー投稿ブロックが固定ページに設置されている場合は実行されません。

    0
    Who liked: No user
    #145423
    林淳一
    参加者
    29

    キタジマ様

    h2に変更できました。

    c-page-header__titleでもh2に変更できました。

    add_filter(
    'snow_monkey_template_part_render',
    function( $html, $slug ) {
    if ( 'template-parts/common/page-header' === $slug ) {
    $html = str_replace( '
    
    <h1 ', '<h2 ', $html );
    $html = str_replace( '
    
    ', '
    
    ', $html );
    return $html;
    }
    return $html;
    },
    10,
    2
    );

    トピック閉じます。

    1
    Who liked:
    #145385
    林淳一
    参加者
    29

    まーちゅう様

    ご返信ありがとうございます、またh1が2つになることを気にしていただき、ありがとうございます。
    固定ページと投稿のc-entry__titleは下記ページを参考にh2に変更しました。

    アーカイブページのc-entry__titleのh1をh2に変更するのは下記コードであっていますでしょうか。

    add_filter(
    	'snow_monkey_template_part_render',
    	function( $html, $slug ) {
    		if ( 'template-parts/archive/entry/header/header' === $slug ) {
    			$html = str_replace( '<h1 ', '<h2 ', $html );
    			$html = str_replace( '</h1>', '</h2>', $html );
    			return $html;
    		}
    		return $html;
    	},
    	10,
    	2
    );
    0
    Who liked: No user
    アバター画像キタジマ タカシ
    参加者
    2619

    snow_monkey_template_part_render_footer フィルターフックでフッターの HTML をカスタマイズできます。

    同期パターンの場合は apply_filters( 'the_content', '<!-- wp:block {"ref":19703} /-->' ) という形でテンプレートから呼び出せます。

    これを組み合わせて、下記のようなコードでフッターの上部に同期パターンを呼び出せるかなと。My Snow Monkey プラグインにコードを追加して試してみてください!

    ref のところの番号はご自身の環境にあわせて変えてください。僕は記事の編集画面で表示したいパターンを配置して、コードエディターに切り替えて確認しました。

    add_filter(
    	'snow_monkey_template_part_render_footer',
    	function( $html ) {
    		return apply_filters( 'the_content', '<!-- wp:block {"ref":19703} /-->' ) . $html;
    	}
    );
    1
    Who liked:
    #144140
    アバター画像キタジマ タカシ
    参加者
    2619

    リプライするときに整形されるから?なのかコードが崩れているので整形してみました。

    あと、コードの途中にちゃんとタグの情報が取得できているか確認するために var_dump(...); を追加してみました。ちゃんと取得できているならタグの情報が画面上に表示されるはずです。表示されないなら紐づけができていないか、名前が間違っている可能性がありそうです。

    add_filter(
    	'snow_monkey_template_part_render_template-parts/loop/entry-summary/title/title',
    	function ($html) {
    		// カスタムフィールドで設定したフィールド名を代入
    		$acf_name_area = get_field('name_area');
    		$acf_region_area = get_field('region_area');
    		$acf_specialty_genre = get_field('specialty_genre');
    
    		// テンプレートのh3タグの後に <div class="property-info">を追加
    		$acf_property_info = '</h3><div class="property-info">' .
    			'<div class="property-body">' .
    			'<div class="property-content">' .
    			'<dl class="name_area"><span>【代表者名】</span> <dt>'  . esc_html($acf_name_area) . '<dt></dl>' .
    			'<dl class="region_area"><span>【地域】</span> <dt>'  . esc_html($acf_region_area) . '<dt></dl>' .
    			'<dl class="specialty_genre"><span>【取扱業務】</span> <dt>'  . esc_html($acf_specialty_genre) . '<dt></dl>' .
    			'</div>' .
    			'</div>' .
    			'</div>';
    
    		// テンプレートパーツのh3タグの後ろにdivタグを追加する
    		$html = str_replace(
    			'</h3>',
    			$acf_property_info,
    			$html
    		);
    
    		return $html;
    
    		// テンプレートパーツのh3タグの後ろにdivタグを追加する
    		$html = str_replace(
    			'</h3>',
    			$acf_property_info,
    			$html
    		);
    
    		// 記事に紐づいている post_tag の各タームのアーカイブページへのリンクを表示する
    		$post_tag_terms = get_the_terms(get_the_ID(), 'administrative_scrivener_tag');
    		var_dump( $post_tag_terms ); // テスト用
    		ob_start();
    		if (is_array($post_tag_terms)) {
    			foreach ($post_tag_terms as $post_tag_term) {
    				?>
    				<a href="<?php echo esc_url( get_term_link( $post_tag_term ) ); ?>"><?php echo esc_html( $post_tag_term->name ); ?></a>
    				<?php
    			}
    		}
    		$administrative_scrivener_tags = ob_get_clean();
    		var_dump( esc_html( $administrative_scrivener_tags ) ); // テスト用
    
    		$html = $html . $administrative_scrivener_tags;
    		return $html;
    	}
    );
    1
    Who liked:
    #144139
    YM
    参加者
    8

    キタジマ様

    早速のご教授ありがとうございます。

    申し訳ありません、return $html;追加と
    タクソノミーnameが「administrative_scrivener_tag」の為
    下記の様にpost_tagの箇所を「administrative_scrivener_tag」に変更いたしましたが表示されない様です。

    
    add_filter(
    'snow_monkey_template_part_render_template-parts/loop/entry-summary/title/title',
    function ($html) {
    // カスタムフィールドで設定したフィールド名を代入
    $acf_name_area = get_field('name_area');
    $acf_region_area = get_field('region_area');
    $acf_specialty_genre = get_field('specialty_genre');
    
    // テンプレートのh3タグの後に
    <div class="property-info">を追加
    $acf_property_info = '
    <div class="property-info">' .
    '
    <div class="property-body">' .
    '
    <div class="property-content">' .
    '
    <dl class="name_area">【代表者名】
     	<dt>' . esc_html($acf_name_area) . '</dt>
     	<dt></dt>
    </dl>
    ' .
    '
    <dl class="region_area">【地域】
     	<dt>' . esc_html($acf_region_area) . '</dt>
     	<dt></dt>
    </dl>
    ' .
    '
    <dl class="specialty_genre">【取扱業務】
     	<dt>' . esc_html($acf_specialty_genre) . '</dt>
     	<dt></dt>
    </dl>
    ' .
    '
    
    </div>
    ' .
    '
    
    </div>
    ' .
    '
    
    </div>
    ';
    
    // テンプレートパーツのh3タグの後ろにdivタグを追加する
    $html = str_replace(
    '
    
    ',
    $acf_property_info,
    $html
    );
    
    return $html;
    
    // テンプレートパーツのh3タグの後ろにdivタグを追加する
    $html = str_replace(
    '
    
    ',
    $acf_property_info,
    $html
    );
    
    return $html;
    
    // 記事に紐づいている post_tag の各タームのアーカイブページへのリンクを表示する
    ob_start();
    $post_tag_terms = get_the_terms(get_the_ID(), 'administrative_scrivener_tag');
    if (is_array($post_tag_terms)) {
    foreach ($post_tag_terms as $post_tag_term) {
    ?>
    <!--?php echo esc_html($post_tag_term->name); ?-->
    <!--?php <br ?--> }
    }
    $html = $html . ob_get_clean();
    return $html;
    }
    );
    

    ご確認いただけますと幸いです。

    お手数おかけいたしますが何卒よろしくお願い申し上げます。

    0
    Who liked: No user
    #144132
    YM
    参加者
    8

    キタジマ様

    早速のご教授ありがとうございます。

    下記コードを追加いたしましたが表示されませんでした。

    ちなみにですが、CPT UIでタクソノミーを追加して表示させている記事に紐付けしております。

    記事自体の表示は、「最近の投稿」で投稿タイプを選んでおります。

    
    
    add_filter(
    	'snow_monkey_template_part_render_template-parts/loop/entry-summary/title/title',
    	function ($html) {
    		// カスタムフィールドで設定したフィールド名を代入
    		$acf_name_area = get_field('name_area');
    		$acf_region_area = get_field('region_area');
    		$acf_specialty_genre = get_field('specialty_genre');
    
    		// テンプレートのh3タグの後に <div class="property-info">を追加
    		$acf_property_info = '</h3><div class="property-info">' .
    			'<div class="property-body">' .
    			'<div class="property-content">' .
    			'<dl class="name_area"><span>【代表者名】</span> <dt>'  . esc_html($acf_name_area) . '<dt></dl>' .
    			'<dl class="region_area"><span>【地域】</span> <dt>'  . esc_html($acf_region_area) . '<dt></dl>' .
    			'<dl class="specialty_genre"><span>【取扱業務】</span> <dt>'  . esc_html($acf_specialty_genre) . '<dt></dl>' .
    			'</div>' .
    			'</div>' .
    			'</div>';
    
    		// テンプレートパーツのh3タグの後ろにdivタグを追加する
    		$html = str_replace(
    			'</h3>',
    			$acf_property_info,
    			$html
    		);
    
    		return $html;
    
    		// テンプレートパーツのh3タグの後ろにdivタグを追加する
    		$html = str_replace(
    			'</h3>',
    			$acf_property_info,
    			$html
    		);
    
    		// 記事に紐づいている post_tag の各タームのアーカイブページへのリンクを表示する
    		ob_start();
    		$post_tag_terms = get_the_terms(get_the_ID(), 'post_tag');
    		if (is_array($post_tag_terms)) {
    			foreach ($post_tag_terms as $post_tag_term) {
    	?>
    			<a href="<?php echo esc_url( get_term_link( $post_tag_term ) ); ?>"><?php echo esc_html( $post_tag_term->name ); ?></a>
    <?php
    			}
    		}
    		$html = $html . ob_get_clean();
    	}
    );

    `

    お手数おかけいたしますが、ご確認の程よろしくお願い申し上げます。

    0
    Who liked: No user
    アバター画像キタジマ タカシ
    参加者
    2619

    どこに出したいかにもよるかなと思いますが、とりあえずフックで出すことはできます。

    add_filter(
    	'snow_monkey_template_part_render_templates/view/full',
    	function( $html, $name ) {
    		// 固定ページのとき
    		if ( 'page' === $name ) {
    			// ランディングページ(ヘッダー・フッターあり)のとき
    			if ( 'blank-content' === \Inc2734\WP_View_Controller\Bootstrap::get_layout() ) {
    				// パンくずを生成
    				ob_start();
    				\Framework\Helper::get_template_part( 'template-parts/common/breadcrumbs' );
    				$breadcrumbs = ob_get_clean();
    
    				// パンくずを出力結果にくっつける
    				$html = $breadcrumbs . $html;
    			}
    		}
    		return $html;
    	},
    	10,
    	2
    );

    表示場所やマークアップを調整したい場合は独自にテンプレートを作ったほうが管理しやすいのかなと思います。

    0
    Who liked: No user
    #143726
    まーちゅう
    参加者
    403

    snow_monkey_template_part_render_<slug>
    snow_monkey_pre_template_part_render_<slug>
    のどちらかのフィルターフックを使用されてはどうでしょうか?

    /**
     * @param $html テンプレートパーツの出力HTML
     * @param $name テンプレートパーツの名前
     * @param $vars テンプレートパーツのリクエスト配列
     */
    add_filter(
    	'snow_monkey_template_part_render_template-parts/loop/entry-summary/title/title',
    	function( $html ) {
    		$html = str_replace(
    			'書き換え前の文字列',
    			'書き換え後の文字列',
    			$html
    		);
    		return $html;
    	},
    	10
    );
    /**
     * @param $html テンプレートパーツの出力HTML
     * @param $name テンプレートパーツの名前
     * @param $vars テンプレートパーツのリクエスト配列
     */
    add_filter(
    	'snow_monkey_pre_template_part_render_template-parts/loop/entry-summary/title/title',
    	function( $html ) {
    		return 'New HTML';
    	},
    	10
    );
    2
    Who liked:
    #143279
    アバター画像キタジマ タカシ
    参加者
    2619

    投稿一覧はそのままで詳細ページでの表示だけ、ということは、あくまで「その記事の装飾としての画像を変えたい」ということだと思ったので、そのやり方を考えてみました。

    post_thumbnail_html で詳細ページだけ表示を変える場合、OGP 画像や関連記事などに使用される画像も変わってしまう可能性があるのでそれ以外を使ったやり方にしてみました。

    「アイキャッチ画像の表示」の選択肢によって対応が変わるので、一応それぞれのパターンについて考えてみました。

    ### 「アイキャッチ画像の位置」が「ページヘッダー」のとき

    // テンプレートパーツに画像の URL を差し替えるオプションがあるのでそれを使う。
    add_filter(
    	'snow_monkey_get_template_part_args_template-parts/common/page-header',
    	function( $args ) {
    		$default_image_url = get_template_directory_uri() . '/wp-content/uploads/2024/12/XXXX.jpeg';
    		$args['vars']['_image'] = '<img src="' . esc_url( $default_image_url ) . '" alt="' . esc_attr( get_the_title() ) . '">';
    		return $args;
    	}
    );

    ### 「アイキャッチ画像の位置」が「コンテンツの上」のとき

    // オプションは無いのでテンプレートパーツ自体を書き換える。
    add_filter(
    	'snow_monkey_template_part_render_template-parts/content/eyecatch',
    	function( $html ) {
    		if ( ! $html ) {
    			return $html;
    		}
    
    		$default_image_url = get_template_directory_uri() . '/wp-content/uploads/2024/12/XXXX.jpeg';
    		$default_image     =
    		ob_start();
    		?>
    		<div class="c-eyecatch">
    			<img src="<?php echo esc_url( $default_image_url ); ?>" alt="<?php echo esc_attr( get_the_title() ); ?>">
    		</div>
    		<?php
    		return ob_get_clean();
    	}
    );
    1
    Who liked:
15件の結果を表示中 - 1 - 15件目 (全254件中)

ドキュメント

Snow Monkey の設定方法やマニュアルを掲載しています。

ドキュメント

フォーラム

Snow Monkey の使い方やカスタマイズについてのご質問・ご要望等はサポートフォーラムで行っています。サポートフォーラムは誰でも閲覧できますが、書き込みできるのは Snow Monkey 購入者のみとなります。

サポートフォーラム

よくあるご質問

Snow Monkey のサービスについて不明な点がある場合は、まずはよくあるご質問をご確認ください。

よくあるご質問

お問い合わせ

よくあるご質問を見ても解決しなかった場合、試用版の申請については問い合わせフォームからお願いいたします。

お問い合わせ

Snow Monkey は Gutenberg ブロックエディターに対応した 100%GPL の WordPress テーマです。拡張性を意識した開発をおこなっており、カスタマイザーとブロックでスピーディーにサイトを立ち上げるだけでなく、CSS やフックを駆使した高度なカスタマイズにも柔軟に対応できます。