简体   繁体   中英

Custom form on WordPress blog

I would like to create a custom form for my WordPress blog which takes the user's email address and then adds it to a database. I know how to write the form and script to achieve the data storage. I don't know how I would go about sticking it on WordPress blog though.

Are there any plugins for this type of thing, or is there a way I can manually add the form to the page?

It's basically a signup for notifications box.

Thanks.

You can just add it using the text widget if your theme is widget ready

Look under appearances>widgets You can add html to text widget

If you are using more than html you'll run into problems with the widget. Upon which I'd recommend that you create a widget yourself.

Here is code for a blank plugin. Add/call your code in the "widget" function.

<?php
/*
Plugin Name: Blank Plugin
Plugin URI: http://www.example.com/plugins/blankPlugin/
Description: This is a plugin template
Author: Your Name
Version: 0.1
Author URI: http://www.example.com/about/
*/

class blankPlugin extends WP_Widget {

 function blankPlugin() {  // The widget construct. Initiating our plugin data.
  $widgetData = array( 'classname' => 'blankPlugin', 'description' => __( "A blank plugin widget" ) );
  $this->WP_Widget('blankPlugin', __('Blank Plugin'), $widgetData);
 } 

 function widget($args, $instance) { // Displays the widget on the screen.
  extract($args);
  echo $before_widget;
  echo $before_title . $instance['title'] . $after_title; 
  echo 'The amount is: '.$instance['amount'];
  echo $after_widget;
 }

 function update($new_instance, $old_instance) { // Updates the settings.
  return $new_instance;
 }

 function form($instance) { // The admin form. 
  $defaults = array( 'title' => 'Wichita', 'amount' => '45' );
  $instance = wp_parse_args($instance, $defaults); ?>
  <div id="blankPlugin-admin-panel">
   <p>
    <label for="<?php echo $this->get_field_id("title"); ?>">Widget title:</label>
    <input type="text" class="widefat" name="<?php echo $this->get_field_name("title"); ?>" id="<?php echo $this->get_field_id("title"); ?>" value="<?php echo $instance["title"]; ?>" />
   </p>
   <p>
    <label for="<?php echo $this->get_field_id("amount"); ?>">An amount:</label>
    <input type="text" class="widefat" name="<?php echo $this->get_field_name("amount"); ?>" id="<?php echo $this->get_field_id("amount"); ?>" value="<?php echo $instance["amount"]; ?>" />
   </p>
  </div>
<?php } 

} 

// Register the widget.
add_action('widgets_init', create_function('', 'return register_widget("blankPlugin");'));
?>

For more information... (see links at the bottom of the page as well) http://codex.wordpress.org/Widgets_API#Developing_Widgets

you can use this wordpress plugin http://wordpress.org/extend/plugins/contact-form-7/

or can do on your own base.

you can create a template inside your theme folder like this:-

<?php
/*Template Name: some thing*/
//your dynamic stuff here

?>

and can assign this template to your static page which you can create from the admin panel of wordpress. whenever you hit the paramalink of this static page this file will be called. thus you can handle the everything mail content etc. Thanks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM