在长回声字符串php中添加div

问题描述

我正在尝试在此回显字符串中添加一个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>';

所以我喜欢在{$ 1}-。cat_name之前添加<span property="name">

在结束</span>之前的结束</a>

谢谢!

解决方法

好的,我已经知道了:

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>';