|
ปกติแล้ว เวลาที่เราทำ album รูปภาพด้วย plugin nextgen ภาพของแต่ละอัลบั้มจะลิงค์ไปยัง page เท่านั้น แต่ในบางกรณีที่เราต้องการให้มันลิงค์ไปยัง หน้า post เรายังลิงค์ไปไม่ได้ เพราะระบบพื้นฐานของ nextgen ไม่ได้ทำการรองรับการลิงค์ไปยังหน้า post โดยตรง แต่วันนี้ MR.WORDPRESS มีทางแก้ให้กับทุกท่านแล้วครับ ไม่ยากอย่างที่คิดเลยนะครับ ค่อยทำไปด้วยกันนะครับ
1.สร้างฟังชั่นในการค้นหา post แต่ละตัว โดยหาไฟล์ plugins/nextgen-gallery/admin/functions.php ให้แทรกโค๊ตข้างล่างนี้ ก่อนแท็กปิด ?> ตัวสุดท้าย
function ngg_dropdown_posts( $default = 0 ) {global $wpdb, $post_ID;$items = $wpdb->get_results( $wpdb->prepare("SELECT ID, post_title FROM $wpdb->posts WHERE post_type = 'post' AND post_status != 'trash' ORDER BY menu_order") );if ( $items ) {foreach ( $items as $item ) { if (!empty ( $post_ID ) ) { if ( $item->ID == $post_ID ) { continue; } } if ( $item->ID == $default) $current = ' selected="selected"'; else $current = ''; echo "nt " . esc_html($item->post_title) . ""; } } else { return false; }}
2. เปิดไฟล์นี้ขึ้นมา plugins/nextgen-gallery/admin/manage-images.php หาโค๊ดนี้
parent_dropdown($gallery->pageid);
แทรกโค๊ดนี้ลงไป ngg_dropdown_posts($gallery->pageid);
3.จาก 2 บรรทัดข้างบนได้สร้าง ฟังชั่นในการดึงหน้าโพสต์เรียบร้อยแล้ว ในขั้นตอนนี้เราจะมาสร้าง Dropdown list ให้เปิดไฟล์นี้ขึ้นมา plugins/nextgen-gallery/admin/manage-images.php หาโค๊ดนี้
<select style="width: 95%;" name="parent_id"> <option value="0"></option> </select><input id="group" class="button-secondary action" name="addnewpage" type="submit" value="<?php _e ('Add page', 'nggallery'); ?>" />
แทรกโค๊ตนี้ : <input id="group" class="button-secondary action" name="addnewpost" type="submit" value="<?php _e ('Add post', 'nggallery'); ?>" />
4.เปิดไฟล์ plugins/nextgen-gallery/admin/manage.php ขึ้นมา และหาโค๊ตนี้ if (isset ($_POST['addnewpage'])) {แทรกโค๊ตนี้ลงไป จะได้ดังนี้
if (isset ($_POST['addnewpost'])) {// Add a new postcheck_admin_referer('ngg_updategallery');$category_id = esc_attr($_POST['category_id']);$gallery_title = esc_attr($_POST['title']);$gallery_name = $wpdb->get_var("SELECT name FROM $wpdb->nggallery WHERE gid = '$this->gid' ");// Create a WP postglobal $user_ID;$post['post_type'] = 'post';$post['post_content'] = '[Gallery not found]';$post['post_parent'] = 0;$post['post_author'] = $user_ID;$post['post_status'] = 'publish';$post['post_title'] = $gallery_title == '' ? $gallery_name : $gallery_title;$post['post_category'] = array($category_id);$post = apply_filters('ngg_add_new_post', $post, $this->gid);$gallery_pageid = wp_insert_post ($post);if ($gallery_pageid != 0) {$result = $wpdb->query("UPDATE $wpdb->nggallery SET title= '$gallery_title', pageid = '$gallery_pageid' WHERE gid = '$this->gid'");nggGallery::show_message( __('New gallery post ID','nggallery'). ' ' . $pageid . ' -> ' . $gallery_title . ' ' .__('created','nggallery') );}}เราก็จะได้ Dropdown ที่มีหน้า Post เอาไว้เลือก Page link to Post กันแบบชื่นบานได้แล้วครับ
- See more at: http://professional-wordpress.co ... thash.XaqRtuE4.dpuf
|