WordPress - 在管理区域的页面上显示帖子内容和帖子
我想在我的WordPress管理区域中创建一个页面,该页面显示帖子摘录和表格式样布局中的各种自定义字段元。WordPress - 在管理区域的页面上显示帖子内容和帖子
如果这是一个前端的WordPress模板,我可以很容易地使用WordPress循环和查询,但是,我不太确定如何在管理区域的页面上执行此操作。
它会是一样的,还是我需要使用一种全新的方法?如果是这样,有人可以提供一个我将如何做到这一点的工作示例?
管理页面将使用我的functions.php中包含的文件创建 - 或者至少这是此刻的计划,所以我只需要帮助确定如何拉动WordPress摘录和发布Meta。
外循环,你将需要使用
$post->post_excerpt
或试试这个
function get_the_excerpt_here($post_id)
{
global $wpdb;
$query = "SELECT post_excerpt FROM $wpdb->posts WHERE ID = $post_id LIMIT 1";
$result = $wpdb->get_results($query, ARRAY_A);
return $result[0]['post_excerpt'];
}
可以使用WP_Query object每次WordPress的初始化后,所以如果你喜欢,你甚至可以使成千上万的如果您想要这样做,可以在WordPress后端嵌套查询。
这是要走的路:
创建一个动作来增加你的后台页面 - 编写一个插件或者把它放到你的functions.php
设置菜单页面 - 代码是一个完整后端管理的示例您的主题的页面
使用WP_Query对象包含您的查询 - 可选地直接进行数据库查询(http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query)。可能使用WordPress的“widefat”类,进行相当的格式化。
-
确保您的变更正确保存
add_action('admin_menu', 'cis_create_menu'); function cis_create_menu() { //create new top-level menu add_menu_page(__('Theme Settings Page',TEXTDOMAIN),__('Configure Theme',TEXTDOMAIN), 'administrator', __FILE__, 'cis_settings_page', ''); //call register settings function add_action('admin_init','cis_register_settings'); } function cis_register_settings() { register_setting('cis-settings-group','cis_options_1','cis_validate_settings'); } function cis_settings_page() { // All Text field settings $op_fields = array( array(__('Label 1','textdomain'),"Description 1") ); ?> <div class="wrap"> <h2><?php echo THEME_NAME; _e(": Settings",TEXTDOMAIN); ?></h2> <?php settings_errors(); ?> <form method="post" action="options.php"> <?php settings_fields('cis-settings-group'); $options = get_option('cis_options_1'); ?> <h3><?php _e('General','textdomain'); ?></h3> <table class="widefat"> <thead> <tr valign="top"> <th scope="row"><?php _e('Setting','ultrasimpleshop'); ?></th> <th scope="row"><?php _e('Value','ultrasimpleshop'); ?></th> <th scope="row"><?php _e('Description','ultrasimpleshop'); ?></th> <th scope="row"><?php _e('ID','ultrasimpleshop'); ?></th> </tr> </thead> <tbody> <?php // the text-settings we define fast display $i=1; foreach($op_fields as $op) {?> <tr valign="top"> <td><label for="cis_oset_<?php echo $i; ?>"><?php echo $op[0]; ?></label></td> <td><input size="100" id="cis_oset_<?php echo $i; ?>" name="cis_options_1[cis_oset_<?php echo $i; ?>]" type="text" value="<?php echo esc_attr($options['cis_oset_'.$i]);?>" /></td> <td class="description"><?php echo $op[1]; ?></td> <td class="description"><?php echo $i; ?></td> </tr> <?php $i++; } ?> </tbody> </table> <p class="submit"> <input type="submit" class="button-primary" value="<?php _e('Save Changes',TEXTDOMAIN) ?>" /> </p> </form> </div> <?php } // Validate the user input - if nothing to validate, just return function cis_validate_settings($input) { $valid = array(); $i= 1; while(isset($input['cis_oset_'.$i])) { $valid['cis_oset_'.$i] = $input['cis_oset_'.$i]; $i++; } $cis_additional_settings = get_option('cis_options_1'); foreach($input as $ikey => $ivalue) { if($ivalue != $valid[$ikey]) { add_settings_error( $ikey, // setting title "cis_oset_".$ikey, // error ID str_replace("%s",$ikey,__('Invalid Setting in Settings Area ("%s"). The value was not changed.',TEXTDOMAIN)), // error message 'error' // type of message ); $valid[$ikey] = $cis_additional_settings[$ikey]; } } return $valid; }
我会在几天内给出这个结果,如果它可行,我会接受它:)非常感谢 – 2012-03-14 13:19:06
您可以创建自己的插件来实现这一目标。 – 2012-03-08 13:11:50