jianghu52
V2EX  ›  问与答

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

  •  
  •   jianghu52 · Mar 19, 2014 · 2487 views
    This topic created in 4462 days ago, the information mentioned may be changed or developed.
    <?php the_content() ?> 与 <?=the_content() ?>
    这样写等效么?两者有什么区别?
    我目前测试的结果是等效的。
    另外,我想在这里面添加图片,但是路径不会写,求教。
    我测试的结果
    <?= the_content("<img src='/images/pc_bt.png' width='120' height='20' />") ?>
    这么写不对,求指导
    3 replies    1970-01-01 08:00:00 +08:00
    Andor_Chen
        1
    Andor_Chen  
       Mar 19, 2014
    1. 不要用简写的 tag,用 <?php ?>;
    2. 图片的路径取决于你的图片放在哪儿,一般如果放在主题文件夹中可以这么写:<?php echo get_template_directory_uri() . 'images/pc_bt.png'; ?>

    多看 WordPress Codex
    qiayue
        2
    qiayue  
    PRO
       Mar 19, 2014   ❤️ 1
    <?=$foo?> 相当于 <?php echo $foo;?>
    <?php the_content(); ?> 是调用 the_content() 函数,<?=the_content()?> 是调用 the_content() 函数,并且打印函数返回值。
    jianghu52
        3
    jianghu52  
    OP
       Mar 20, 2014
    @qiayue 非常感谢,你这么说我就明白了。因为 the_content() 函数本身就在函数内有echo输出的内容,所以在wordpress上是等效的。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2663 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 10:31 · PVG 18:31 · LAX 03:31 · JFK 06:31
    ♥ Do have faith in what you're doing.