Php 在多个选项卡中使用相同的功能
我有一个php脚本,可以呈现几个选项卡 在每个选项卡中都有一个代码,该代码在几个选项卡中重复,这使得更新过程变得困难 示例:Php 在多个选项卡中使用相同的功能,php,wordpress,Php,Wordpress,我有一个php脚本,可以呈现几个选项卡 在每个选项卡中都有一个代码,该代码在几个选项卡中重复,这使得更新过程变得困难 示例: <div id="1" class="tabcontent"> <?php if (!empty( $_POST['newtags'] ) ) { wp_set_post_tags( $post->ID, $_POST['newtags'], true ); } ?> </div> <div id="2" class="
<div id="1" class="tabcontent">
<?php
if (!empty( $_POST['newtags'] ) ) {
wp_set_post_tags( $post->ID, $_POST['newtags'], true );
} ?>
</div>
<div id="2" class="tabcontent">
<?php
if (!empty( $_POST['h2'])){ // if the input field is not empty
update_post_meta($post->ID, 'description', $concatenated_description, $description_field );
}?>
</div>
<div id="3" class="tabcontent">
<?php
if (!empty( $_POST['newtags'] ) ) {
wp_set_post_tags( $post->ID, $_POST['newtags'], true );
} ?>
</div>
function set_newtags() {
if (!empty( $_POST['newtags'] ) ) {
wp_set_post_tags( $post->ID, $_POST['newtags'], true );
}
}
function set_newmeta() {
if (!empty( $_POST['h2'])){ // if the input field is not empty
update_post_meta($post->ID, 'description', $concatenated_description, $description_field );
}
}
<div id="1" class="tabcontent">
<?php set_newtags() ?>
</div>
<div id="2" class="tabcontent">
<?php set_newmeta() ?>
</div>
<div id="3" class="tabcontent">
<?php set_newtags() ?>
</div>
(这样,我只需要更新一个函数,而不是在多个选项卡中更新多个代码副本)
和than,在各自的选项卡中调用它们,如下所示:
<div id="1" class="tabcontent">
<?php
if (!empty( $_POST['newtags'] ) ) {
wp_set_post_tags( $post->ID, $_POST['newtags'], true );
} ?>
</div>
<div id="2" class="tabcontent">
<?php
if (!empty( $_POST['h2'])){ // if the input field is not empty
update_post_meta($post->ID, 'description', $concatenated_description, $description_field );
}?>
</div>
<div id="3" class="tabcontent">
<?php
if (!empty( $_POST['newtags'] ) ) {
wp_set_post_tags( $post->ID, $_POST['newtags'], true );
} ?>
</div>
function set_newtags() {
if (!empty( $_POST['newtags'] ) ) {
wp_set_post_tags( $post->ID, $_POST['newtags'], true );
}
}
function set_newmeta() {
if (!empty( $_POST['h2'])){ // if the input field is not empty
update_post_meta($post->ID, 'description', $concatenated_description, $description_field );
}
}
<div id="1" class="tabcontent">
<?php set_newtags() ?>
</div>
<div id="2" class="tabcontent">
<?php set_newmeta() ?>
</div>
<div id="3" class="tabcontent">
<?php set_newtags() ?>
</div>
问题?这不起作用
“我做错了什么?”如果在这些函数中使用
return
,比如return update\u post...