V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
jianghu52
V2EX  ›  问与答

求问一个关于 wordpress 的写法问题。

  •  
  •   jianghu52 · 2014-03-19 18:36:04 +08:00 · 1977 次点击
    这是一个创建于 3700 天前的主题,其中的信息可能已经有所发展或是发生改变。
    <?php the_content() ?> 与 <?=the_content() ?>
    这样写等效么?两者有什么区别?
    我目前测试的结果是等效的。
    另外,我想在这里面添加图片,但是路径不会写,求教。
    我测试的结果
    <?= the_content("<img src='/images/pc_bt.png' width='120' height='20' />") ?>
    这么写不对,求指导
    3 条回复    1970-01-01 08:00:00 +08:00
    Andor_Chen
        1
    Andor_Chen  
       2014-03-19 20:00:41 +08:00
    1. 不要用简写的 tag,用 <?php ?>;
    2. 图片的路径取决于你的图片放在哪儿,一般如果放在主题文件夹中可以这么写:<?php echo get_template_directory_uri() . 'images/pc_bt.png'; ?>

    多看 WordPress Codex
    qiayue
        2
    qiayue  
       2014-03-19 20:34:35 +08:00   ❤️ 1
    <?=$foo?> 相当于 <?php echo $foo;?>
    <?php the_content(); ?> 是调用 the_content() 函数,<?=the_content()?> 是调用 the_content() 函数,并且打印函数返回值。
    jianghu52
        3
    jianghu52  
    OP
       2014-03-20 09:54:20 +08:00
    @qiayue 非常感谢,你这么说我就明白了。因为 the_content() 函数本身就在函数内有echo输出的内容,所以在wordpress上是等效的。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3532 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 04:59 · PVG 12:59 · LAX 21:59 · JFK 00:59
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.