我对PHP知之甚少。我正在为我的Wordpress主题创建一个设置页面。我想用index.php中的文本框更改index.php中的文本。我尝试了太多方法。我在index.php中的tag中分配了name,id,value就像在我的functions.php源代码中的aboutustitle一样。但我没有这样做。我怎样才能做到这一点?
我的代码在这里
<?php
// create custom plugin settings menu
add_action('admin_menu', 'my_cool_plugin_create_menu');
function my_cool_plugin_create_menu() {
//create new top-level menu
add_menu_page('Yankı Tema Ayarlar', 'Tema Ayaları', 'administrator', __FILE__, 'my_cool_plugin_settings_page' , plugins_url('/images/icon.png', __FILE__) );
//call register settings function
add_action( 'admin_init', 'register_my_cool_plugin_settings' );
}
function register_my_cool_plugin_settings() {
//register our settings
register_setting( 'my-cool-plugin-settings-group', 'aboutustitle' );
register_setting( 'my-cool-plugin-settings-group', 'some_other_option' );
register_setting( 'my-cool-plugin-settings-group', 'option_etc' );
}
function my_cool_plugin_settings_page() {
?>
<div class="wrap">
<h1>Tema Ayarları</h1>
<p>Tema ayarlarınızı buradan düzenleyebilirsiniz</p>
<form method="post" action="options.php">
<?php settings_fields( 'my-cool-plugin-settings-group' ); ?>
<?php do_settings_sections( 'my-cool-plugin-settings-group' ); ?>
<table class="form-table">
<h2>Hakkımızda Kısmı</h2>
<tr valign="top">
<th scope="row">Başlık</th>
<td><input type="text" name="aboutustitle" value="<?php echo esc_attr( get_option('aboutustitle') ); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row">Açıklama</th>
<td><input type="text" name="some_other_option" value="<?php echo esc_attr( get_option('some_other_option') ); ?>" /></td>
</tr>
</table>
<?php submit_button(); ?>
</form>
</div>
<?php } ?>
答案 0 :(得分:1)
您可以使用以下方法在Wordpress中回显选项:
<p><?php echo get_option( 'option_name' ); ?></p>
https://developer.wordpress.org/reference/functions/get_option/
答案 1 :(得分:0)
不知道你到底意味着什么
但是如果你想要包含一些东西,你可以使用这个
<?php include 'functions.php';?>
例如这是我的索引php
<!DOCTYPE html>
<html>
<body>
<h1>Welcome to my home page!</h1>
<?php include 'functions.php';
echo "I have a $color $car.";
?>
</body>
</html>
并在我的函数php
<?php
$color = "red"
$car = "BMW" ?>
所以输出是
I have a red BMW