web-dev-qa-db-ja.com

bloginfo( 'stylesheet_directory')対get_stylesheet_directory_uri()そしてinclude( 'file.php')vs get_template_part()

私のカスタムテーマでは、私は私のカスタムロゴをロードするために<img src="<?php bloginfo('stylesheet_directory'); ?>/images/logo.jpg"/>を使っています。

私はfront-page.phpにカスタムサイドバーを使っています、そしてそれを得るために私が<?php include('sidebar-front.php') ?>を使ったのはそのためです。

しかし、 'theme-check'プラグインを使用しているときは、次のように変更することをお勧めします。

  • bloginfo('stylesheet_directory')からget_stylesheet_directory_uri()
  • include()からget_template_part()

それで、私は以下をしました:

  • <img src="<?php get_stylesheet_directory_uri(); ?>/images/logo.jpg"/>
  • <?php get_template_part('sidebar-front.php') ?>

しかし、両方ともここで失敗しました。ロゴはロードされず、サイドバーもロードされません。私は<?php get_sidebar('front'); ?>を使用しました、そしてそれはうまく機能しています。

私はただそれらの提案の問題点を推測したいのですか?これはWP 3.4.2です。

3
Mayeenul Islam

get_stylesheet_directory_uri()は値を返しますが、何も表示しません。だからあなたは使用する必要があります:

echo get_stylesheet_directory_uri();

get_template_part()locate_template()の単なるラッパーです。しかし、後者には1つの利点があります。見つかったファイルのパスを返します。以下を試してください。

$path = locate_template( 'sidebar-front.php', TRUE );
echo $path;
5
fuxia