我有以下代码
<?php the_content(); ?> 它显示了我的站点的优惠券的描述,
我想使用以下代码在末尾添加每个商店的名称
at <?php echo appthemes_get_custom_taxonomy($post->ID, APP_TAX_STORE, 'name'); ?>例如,它将显示在6pm.com的衣服折扣为.20%。
到目前为止,当我添加代码时,它会分离并创建一个新的段落,如下所示.........
衣服八折。
在6pm.com。
我如何将其合并为一句话。
下面是完整的优惠券函数
<!-- #coupon-main -->
</div> <!-- #head-box -->
<div class="box-bottom"> </div>
<div class="text-box">
<?php appthemes_before_post_content(); ?>
<?php the_content(); ?>
<?php clpr_edit_coupon_link(); ?>
<?php clpr_reset_coupon_votes_link(); ?>
<?php appthemes_after_post_content(); ?>
</div> 发布于 2012-08-04 07:43:36
WordPress可能会在编辑器内的内容周围添加一个<p></p>,该the将保存在帖子的内容中。您可以使用get_the_content()并检查它是否以</p>结尾,如果是,则删除它,echo商店的名称,然后在后面重新添加</p>。
<?php
$content = trim(get_the_content());
if(substr($content, -4) == '</p>') {
echo substr($content, 0, -4);
echo appthemes_get_custom_taxonomy($post->ID, APP_TAX_STORE, 'name');
echo '</p>';
}
else{
echo $content, appthemes_get_custom_taxonomy($post->ID, APP_TAX_STORE, 'name');
}发布于 2012-08-06 22:11:44
<?php
$content = trim(get_the_content());
if(substr($content, -4) == '</p>') {
echo substr($content, 0, -4);
echo appthemes_get_custom_taxonomy($post->ID, APP_TAX_STORE, 'name');
echo '</p>';
}
else{
$content = preg_replace("/\.$/"," ",$content);
echo $content, appthemes_get_custom_taxonomy($post->ID, APP_TAX_STORE, 'name');
} ?>https://stackoverflow.com/questions/11804633
复制相似问题