2012-03-01 225 views
0

我想在我的WordPress管理區域中創建一個頁面,該頁面顯示帖子摘錄和表格式樣佈局中的各種自定義字段元。WordPress - 在管理區域的頁面上顯示帖子內容和帖子

如果這是一個前端的WordPress模板,我可以很容易地使用WordPress循環和查詢,但是,我不太確定如何在管理區域的頁面上執行此操作。

它會是一樣的,還是我需要使用一種全新的方法?如果是這樣,有人可以提供一個我將如何做到這一點的工作示例?

管理頁面將使用我的functions.php中包含的文件創建 - 或者至少這是此刻的計劃,所以我只需要幫助確定如何拉動WordPress摘錄和發佈Meta。

+0

您可以創建自己的插件來實現這一目標。 – 2012-03-08 13:11:50

回答

2

外循環,你將需要使用

$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']; 
} 
3

可以使用WP_Query object每次WordPress的初始化後,所以如果你喜歡,你甚至可以使成千上萬的如果您想要這樣做,可以在WordPress後端嵌套查詢。

這是要走的路:

  1. 創建一個動作來增加你的後臺頁面 - 編寫一個插件或者把它放到你的functions.php

  2. 設置菜單頁面 - 代碼是一個完整後端管理的示例您的主題的頁面

  3. 使用WP_Query對象包含您的查詢 - 可選地直接進行數據庫查詢(http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query)。可能使用WordPress的「widefat」類,進行相當的格式化。

  4. 確保您的變更正確保存

     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; 
         } 
    
+0

我會在幾天內給出這個結果,如果它可行,我會接受它:)非常感謝 – 2012-03-14 13:19:06

相關問題