[英]Combine php functions in wordpress
I have the below code 我有以下代码
<?php the_content(); ?>
and it displays the description of a coupon for my site, 它显示了我网站的优惠券的描述,
I want to add the name of each store at the end, using the following code 我想使用以下代码在最后添加每个商店的名称
at <?php echo appthemes_get_custom_taxonomy($post->ID, APP_TAX_STORE, 'name'); ?>
so for example it will say............20% off clothing at 6pm.com. 因此,举例来说,它会说............在6pm.com脱衣服20%。
As of now when I add code it separates and creates a new paragraph like below......... 到目前为止,当我添加代码时,它会分开并创建一个新的段落,如下所示.........
20% off clothing. 服装减20%。
at 6pm.com. 在6pm.com。
How do I combine this as one sentence. 我如何将其组合为一个句子。
Here is entire coupon function 这是完整的优惠券功能
<!-- #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>
WordPress is likely adding a <p></p>
around your content inside of the editor, which is getting saved in the content of the post. WordPress可能会在编辑器内的内容周围添加
<p></p>
,该内容将保存在帖子内容中。 You can use get_the_content()
and check to see if it ends with a </p>
, and if it does, remove it, echo
the name of the store, and then re-add the </p>
after that. 您可以使用
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');
}
<?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');
} ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.