在WordPress中,我一直在安装和使用各种主题,包括2013、Roots和现在的BlankSlate。我注意到现在我激活了BlankSlate,函数get_template_directory()
用于首页。php仍在返回根主题目录的路径。我当前的头版。php如下所示。
<?php get_header(); ?>
<section id="content" role="main">
<img class="frontpageimg" src="<?php get_template_directory(); ?>/images/slogan-2.png">
<h4>In the Los Angeles area? </h4> <p>Ask about free demo loaners! </p>
<h4>We also take mail orders.</h4> On all orders, there is a 30-day return policy!</p>
<img src = "<?php get_template_directory(); ?>/assets/img/cables-ers-absorber-700.jpg"/></a>
<img src = "<?php get_template_directory(); ?>/assets/img/blueprint-silencers-v2-700.jpg"/></a>
<img src = "<?php get_template_directory(); ?>/assets/img/brav-front-page-700.jpg"/></a>
<a href="contact" class="btn btn-lg btn-orange">Contact Us</a>
</section>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
编辑更新:进行了一些调试,如下所示:停用所有插件。注销,清除缓存。问题仍然存在。
从BlankSlate(问题显而易见)切换到2013主题。类似的行为,虽然我现在可以更具体地说那是什么行为。在2013年的主题中,显然PHP构造<?php echo get_template_directory(); ?>/path-in-2013-theme/file.jpg
有效,但<?php get_template_directory(); ?>
返回根主题的路径。这同样适用于<?php echo get_template_directory_uri(); ?>
(正确使用echo
但并非没有)。
然而,BlankSlate中的行为有些不同。没有echo
二者都get_template_directory()
和get_template_directory_uri()
返回根主题的路径,同时使用echo
他们做了一些其他的事情(但我不确定那是什么……我如何转储这些值以进行调试?)
进一步调试:
我可以用Firebug检查页面源代码。果然,这些函数没有回声就没有输出。所以图像来源是src="/assets/img/brav-banner-3.jpg
等等这在一些主题中起到了作用。我的意思是我可以看到图像。那么可能是缓存问题?当我添加echo并更改jpg的路径时,我能够让它在BlankSlate主题中工作。所以我将把这个问题标记为已解决,作为一个缓存问题。