doutian4046 2015-06-03 08:52
浏览 33
已采纳

如何在html中正确插入此php片段?

I have this php snippet:

<div class="overlay-content">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<i class="fa fa-search"></i></a>
</div>

I would like to remove:

<i class="fa fa-search"></i>

And instead, insert the title attribute, called via php, where currently, the Font-Awesome icon sits -- within the hyperlink. That way, when a visitor hovers over an item, they will see the title instead of a Font Awesome search icon.

So I've tried:

<div class="overlay-content">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php the_title_attribute(); ?></a>
</div>

And that was not successful for reasons perhaps obvious to php developers. Is what I'm trying to do possible? Any guidance in helping me achieve this properly would be greatly appreciated!

  • 写回答

5条回答 默认 最新

  • dongshao8125 2015-06-03 09:03
    关注

    The correct code, that doesn't duplicate echo, should be as follows:

    <div class="overlay-content">
        <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
            <?php the_title(); ?>
        </a>
    </div>
    

    As I've mentioned in my comments, the_permalink() and the_title_attribute() already echo content. No need to add another echo before each.

    You should also (usually) favor the_title() over the_title_attribute() for the actual display of the title.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大