0

我制作了一个 wordpress 插件,我想在其中从数据库中获取数据并需要分页,我使用了 digg 样式分页,但是当我单击分页的下一个链接时,“您没有足够的权限访问此页面。” 这个错误出现请帮助哪里有问题这是我的代码

<?php
include('pagination.class.php');
?>
<?php
/*
Plugin Name:Register Data
Description:Pagination Plugin for wordpress admin Panel.
Author:Pawan Sharma
Author URI:

*/
$object = new YourPlugin();

//add a hook into the admin header to check if the user has agreed to the terms and conditions.
//add_action('admin_head', array($object, 'adminHeader'));

//add footer code
//add_action( 'admin_footer', array($object, 'adminFooter'));

// Hook for adding admin menus
add_action('admin_menu', array($object, 'addMenu'));

//This will create [yourshortcode] shortcode
add_shortcode('yourshortcode', array($object, 'shortcode'));

class YourPlugin{

/**
* This will create a menu item under the option menu
* @see http://codex.wordpress.org/Function_Reference/add_options_page
*/
public function addMenu(){
add_options_page('Regeter Data', 'Regeter Data', 'manage_options', 'my-unique-identifier', array($this, 'optionPage'));
}

/**
* This is where you add all the html and php for your option page
* @see http://codex.wordpress.org/Function_Reference/add_options_page
*/
public function optionPage(){
$items = mysql_num_rows(mysql_query("SELECT * FROM wp_register_form;")); // number of total rows in the database

if($items > 0) {
$p = new pagination;
$p->items($items);
$p->limit(5); // Limit entries per page
$p->target("$this->target?page=list_record");
$p->currentPage($_GET[$p->paging]); // Gets and validates the current page
$p->calculate(); // Calculates what to show
$p->parameterName('paging');
$p->adjacents(1); //No. of page away from the current page

if(!isset($_GET['paging'])) {
$p->page = 1;
} else {
$p->page = $_GET['paging'];
}

//Query for limit paging
$limit = "LIMIT " . ($p->page - 1) * $p->limit . ", " . $p->limit;

} else {
echo "No Record Found";
}

?>
<?php
//Now we'll display the list of records
?>
<div class="wrap">
<h2>List of Records</h2>

<div class="tablenav">
<div class='tablenav-pages'>
<?php echo $p->show(); // Echo out the list of paging. ?>
</div>
</div>

<table class="widefat">
<thead>
<tr>
<th>Name</th>
<th>City</th>
<th>Mobile No</th>
<th>Email</th>
<th>Address</th>
<th>View</th>
</tr>
</thead>
<tbody>
<?php
$sql = "SELECT * FROM wp_register_form $limit";
$result = mysql_query($sql) or die ('Error, query failed');

if (mysql_num_rows($result) > 0 ) {
while ($row = mysql_fetch_assoc($result)) {
$name = $row['customer_name'];
$city = $row['customer_city'];
$phone = $row['customer_phone'];
$email = $row['customer_email'];
$address = $row['customer_address'];
$id = $row['customer_id'];?>

<tr>
<td><?php echo $name; ?></td>
<td><?php echo $city; ?></td>
<td><?php echo $phone; ?></td>
<td><?php echo $email; ?></td>
<td><?php echo $address; ?></td>
<td><?php echo "<a href='http://localhost/wor/wp-content/themes/mitfitness/single_details.php?id=".$id."'>View Details</a>"?></td>
</tr>
<?php }
} else { ?>
<tr>
<td>No Record Found!</td>
<tr>
<?php } ?>
</tbody>
</table>
</div>
<?php
}

/**
* this is where you add the code that will be returned wherever you put your shortcode
* @see http://codex.wordpress.org/Shortcode_API
*/
public function shortcode(){
return "add your image and html here...";
}
}
?>
4

1 回答 1

0

目标有误

<?php
include('pagination.class.php');
?>
<?php
/*
Plugin Name:Register Data
Description:Pagination Plugin for wordpress admin Panel.
Author:Pawan Sharma
Author URI:

*/
$object = new RegisterData();

//add a hook into the admin header to check if the user has agreed to the terms and conditions.
//add_action('admin_head',  array($object, 'adminHeader'));

//add footer code
//add_action( 'admin_footer',  array($object, 'adminFooter'));

// Hook for adding admin menus
add_action('admin_menu',  array($object, 'addMenu'));

//This will create [yourshortcode] shortcode
add_shortcode('yourshortcode', array($object, 'shortcode'));

class RegisterData{

    /**
     * This will create a menu item under the option menu
     * @see http://codex.wordpress.org/Function_Reference/add_options_page
     */
    public function addMenu(){
        add_options_page('Regeter Data', 'Regeter Data', 'manage_options', 'register_data', array($this, 'optionPage'));
    }

    /**
     * This is where you add all the html and php for your option page
     * @see http://codex.wordpress.org/Function_Reference/add_options_page
     */
    public function optionPage(){
       $items = mysql_num_rows(mysql_query("SELECT * FROM wp_register_form;")); // number of total rows in the database

        if($items > 0) {
        $p = new pagination;
        $p->items($items);
        $p->limit(5); // Limit entries per page
        $p->target("$this->target?page=register_data");
        $p->currentPage($_GET[$p->paging]); // Gets and validates the current page
        $p->calculate(); // Calculates what to show
        $p->parameterName('paging');
        $p->adjacents(1); //No. of page away from the current page

        if(!isset($_GET['paging'])) {
            $p->page = 1;
        } else {
            $p->page = $_GET['paging'];
        }

        //Query for limit paging
        $limit = "LIMIT " . ($p->page - 1) * $p->limit  . ", " . $p->limit;

} else {
    echo "No Record Found";
}

?>
 <?php
//Now we'll display the list of records
 ?>
<div class="wrap">
    <h2>List of Records</h2>

<div class="tablenav">
    <div class='tablenav-pages'>
        <?php echo $p->show();  // Echo out the list of paging. ?>
    </div>
</div>

<table class="widefat">
<thead>
    <tr>
        <th>Name</th>
        <th>City</th>         
        <th>Mobile No</th>
        <th>Email</th>
        <th>Address</th>
        <th>View</th>
    </tr>
</thead>
<tbody>
<?php 
$sql = "SELECT * FROM wp_register_form $limit";
$result = mysql_query($sql) or die ('Error, query failed');

if (mysql_num_rows($result) > 0 ) {
    while ($row = mysql_fetch_assoc($result)) {
            $name            = $row['customer_name'];
            $city  = $row['customer_city'];
            $phone       = $row['customer_phone'];
            $email       = $row['customer_email'];
            $address       = $row['customer_address'];
            $id       = $row['customer_id'];?>

        <tr>
            <td><?php echo $name; ?></td>
            <td><?php echo $city; ?></td>
            <td><?php echo $phone; ?></td>
            <td><?php echo $email; ?></td> 
            <td><?php echo $address; ?></td> 
            <td><?php echo "<a href='$this->target?page=register_data&view=".$id."'>View Details</a>"?></td>            
        </tr>
<?php }
} else { ?>
        <tr>
        <td>No Record Found!</td>
        <tr> 
<?php } ?>
</tbody>
</table>
</div>
<?php 
    }

    /**
     * this is where you add the code that will be returned wherever you put your shortcode
     * @see http://codex.wordpress.org/Shortcode_API
     */
    public function shortcode(){
        return "add your image and html here...";
    }

}
?>
于 2013-04-06T10:27:05.613 回答