【问题标题】:Adding div inside long echo string php在长回显字符串php中添加div
【发布时间】:2020-08-24 13:15:03
【问题描述】:

我正在尝试在这个 echo 字符串中添加一个 div,查看了所有其他主题,但这个字符串比那里讨论的问题要复杂一些。

完整代码:

          <div class="breadcrumb hidden-xs" typeof="BreadcrumbList" vocab="https://schema.org/">     
          <span property="itemListElement" typeof="ListItem"><a property="item" typeof="WebPage" class="home" href="<?php echo home_url('/');?>" title="<?php echo bloginfo('name');?>"><span property="name">Home</span></a><meta property="position" content="1"></span><span class="division">/</span><span property="itemListElement" typeof="ListItem"><a property="item" typeof="WebPage" class="post-root post post-post" href="<?php echo home_url('/blog/');?>" title="Ga naar Nieuws."><span property="name">Nieuws</span></a><meta property="position" content="2"></span><span class="division">/</span>
    <span property="itemListElement" typeof="ListItem">
                <?php
$categories = get_the_category();
$separator = ',';
$output = '';
if($categories){
  $i=1;
  foreach($categories as $category) {
      if($i==1){
      if($category->cat_name!="Homepage"){
    echo '<a property="item" typeof="WebPage" href="'.get_category_link( $category->term_id ).'" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '">'.$category->cat_name.'</a>';
  $i++; } } } } ?>
      <meta property="position" content="3"></span>
    <span class="division">/</span><span property="itemListElement" typeof="ListItem"><span property="name"><?php the_title();?></span><meta property="position" content="4"></span></div>

我需要编辑的代码:

echo '<a property="item" typeof="WebPage" href="'.get_category_link( $category->term_id ).'" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '">'.$category->cat_name.'</a>';

所以我喜欢在 .$category->cat_name 之前添加 &lt;span property="name"&gt;

以及结束&lt;/span&gt;之前的结束&lt;/a&gt;

提前致谢!

【问题讨论】:

  • 看看PHP中的字符串连接是如何工作的,然后你就可以弄清楚了。

标签: php wordpress echo breadcrumbs


【解决方案1】:

好的,我已经知道了:

echo '<a property="item" typeof="WebPage" href="'.get_category_link( $category->term_id ).'" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '">' . '<span property="name">'.$category->cat_name.'</span></a>';

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-02
    • 2015-07-02
    • 2011-09-10
    • 1970-01-01
    • 2019-07-11
    相关资源
    最近更新 更多