[英]Combine php functions in wordpress
我有以下代碼
<?php the_content(); ?>
它顯示了我網站的優惠券的描述,
我想使用以下代碼在最后添加每個商店的名稱
at <?php echo appthemes_get_custom_taxonomy($post->ID, APP_TAX_STORE, 'name'); ?>
因此,舉例來說,它會說............在6pm.com脫衣服20%。
到目前為止,當我添加代碼時,它會分開並創建一個新的段落,如下所示.........
服裝減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>
WordPress可能會在編輯器內的內容周圍添加<p></p>
,該內容將保存在帖子內容中。 您可以使用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.