【发布时间】: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 之前添加 <span property="name">。
以及结束</span>之前的结束</a>
提前致谢!
【问题讨论】:
-
看看PHP中的字符串连接是如何工作的,然后你就可以弄清楚了。
标签: php wordpress echo breadcrumbs