2014年08月25日 WordPressphp

現在のテンプレートファイル名の拡張子を除いた名前をbodyのidに設定したかったので、テンプレートファイル名を取得する方法を調べました。
WordPressのトップページとカテゴリページでデザインを変えたい場合などに役立つかと思います。

global $template;
$template_file_name = basename($template, '.php');

この投稿へのコメント

コメントはまだありません。

コメントを残す

メールアドレスが公開されることはありません。

次のHTML タグと属性が使えます。
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

CAPTCHA


ピックアップ記事

WordPressでindex.htmlとindex.phpを混在させる

2011年06月14日 WordPress
なんともない話題ではありますが、既存のサイトを公開したまま、index.phpの方で、WordPressを入れて、リニューアルをと思ってたんですが、index.phpもindex.htmlもWordPressのホームディレクトリにリダイレクトされてるようです。 どうしたもんかと思ってたら、簡単に解決する方法がありました。 wp-include内のcanonical.phpファイルを開き、270行…
「WordPressでindex.htmlとindex.phpを混在させる」をはてなブックマークに追加

ZenCartのパンくずリストをトップページのみ非表示にする

2012年02月11日 zencartphp
変更する箇所 includes/classes/breadcrumb.php の60行目付近 [php] } else { $trail_string .= $this->_trail[$i]['title']; } [/php] 上記のコードを以下に変更します。 [php] } else { if ($this->…
「ZenCartのパンくずリストをトップページのみ非表示にする」をはてなブックマークに追加

wordpress 現在のuser_idやdisplay_nameを取得

2020年01月14日 WordPress
現在のuser_idを取得 [php] $user_id = get_current_user_id();[/php] 現在のdisplay_nameを取得 [php]$user = wp_get_current_user(); $display_name = $user->display_name;[/php]
「wordpress 現在のuser_idやdisplay_nameを取得」をはてなブックマークに追加

WordPressで特定の親カテゴリとその子カテゴリに所属する場合の条件分岐の方法

2022年11月12日 WordPress
functions.phpに以下を記述 [php]if ( ! function_exists( 'post_is_in_descendant_category' ) ) { function post_is_in_descendant_category( $cats, $_post = null ) { foreach ( (array) $cats as $c…
「WordPressで特定の親カテゴリとその子カテゴリに所属する場合の条件分岐の方法」をはてなブックマークに追加

記事IDからリンクを設定

2011年11月21日 WordPress
コード記述例: [php]<p><a href="<?php echo get_permalink(5); ?>">記事ID5へのリンク</a></p> [/php] 出力例: …
「記事IDからリンクを設定」をはてなブックマークに追加
© graffiti on the web . All rights reserved. WordPress Theme by comfy