如何显示此功能?

时间:2019-08-11 作者:Abhijith-cloud

我想将此页面添加到我的页面。php。有人帮我吗?

if(function_exists(\'add_theme_support\')){
      add_theme_support(\'post-thumbnails\'); 
      }


      function mallu_link_add_meta_box(){
      $screens = array( \'post\', \'page\' );
      foreach ( $screens as $screen ) {
      add_meta_box(\'action_block\', \'Action Block\', \'mallu_link_meta_box_callback\', $screen, \'normal\'); 
      }
      }

      // Add meta boxes for action section on each post/page
      add_action(\'add_meta_boxes\', \'mallu_link_add_meta_box\');

      function mallu_link_meta_box_callback($post){
      // Security check
      wp_nonce_field(\'mallu_link_save_meta_box_data\', \'mallu_link_meta_box_nonce\');

      // Get values of the action block fields
      $action_prompt_text = get_post_meta($post->ID, \'mallu_link_meta_prompt_text\', true);
      $action_button_text = get_post_meta($post->ID, \'mallu_link_meta_button_text\', true);
      $action_button_link = get_post_meta($post->ID, \'mallu_link_meta_button_link\', true);


      // Display and populate fields from the database if it exists
      ?>
      <p>
      <label for="action_prompt_text">Action Prompt</label><br>
      <input class="widefat" type="text" name="action_prompt_text" id="action_prompt_text" placeholder="This should be short, to the point and less salesy." value="<?php echo esc_attr($action_prompt_text); ?>">
      </p>
      <p>
      <label for="action_button_text">Action Button Text</label><br>
      <input class="widefat" type="text" name="action_button_text" id="action_button_text" placeholder="This should prompt the visitor to take an action." value="<?php echo esc_attr($action_button_text); ?>">
      </p>
      <p>
      <label for="action_button_link">Action Button Link</label><br>
      <input class="widefat" type="url" name="action_button_link" id="action_button_link" placeholder="Copy and paste the link from the intended page." value="<?php echo esc_attr($action_button_link); ?>">
      </p>
      <?php
      }
      // Callback for saving metaboxes
      function mallu_link_save_meta_box_data($post_id) {


      // Security checks
      if(!isset($_POST[\'mallu_link_meta_box_nonce\'])) return;
      if(!wp_verify_nonce($_POST[\'mallu_link_meta_box_nonce\'], \'mallu_link_save_meta_box_data\')) return;
      if(defined(\'DOING_AUTOSAVE\') && DOING_AUTOSAVE) return;

      if ( isset( $_POST[\'post_type\'] ) && \'page\' == $_POST[\'post_type\'] ) {
        if ( ! current_user_can( \'edit_page\', $post_id ) ) {
          return;
        }
      } else {
        if ( ! current_user_can( \'edit_post\', $post_id ) ) {
          return;
        }
      }

      // Do the save/update
      if(isset($_POST[\'action_prompt_text\'])){
        update_post_meta($post_id, \'mallu_link_meta_prompt_text\', sanitize_text_field($_POST[\'action_prompt_text\']));
      }
      if(isset($_POST[\'action_button_text\'])){
        update_post_meta($post_id, \'mallu_link_meta_button_text\', sanitize_text_field($_POST[\'action_button_text\']));
      }
      if(isset($_POST[\'action_button_link\'])){
        update_post_meta($post_id, \'mallu_link_meta_button_link\', esc_url($_POST[\'action_button_link\']));
      }
      }

      // Save action block details when the post is saved/updated
      add_action(\'save_post\', \'mallu_link_save_meta_box_data\');
I added this code in single.php but not showing

<p><?php echo esc_attr( get_post_meta( get_the_ID(), \'mallu_link_meta_prompt_text\', true ) ); ?></p>
But not displaying. please help

1 个回复
最合适的回答,由SO网友:Wordpress Dev 整理而成

在函数中添加函数代码。php。然后打单曲。php

相关推荐

Vagrant Access index.php

我相信这是一个合适的地方。首先,我安装了VirtualBox和Vagrant。在那之后,我将cd刻录到以下内容:https://github.com/LearnWebCode/vagrant-lamp (下载了zip,提取了文件夹)然后在运行vagrant up之后,我到达了Congratulations 通过IP分页http://192.168.56.101/之后,我在hosts文件中设置了一个易于阅读的URL,并可以运行它,但它会导致出现祝贺页面,而不是索引。php的Hello World。你知道怎么