carlbenton
Forum Replies Created
-
Forum: Plugins
In reply to: [Plugin: NextGEN Gallery] Album thumbnail link to post, not pageHere is a fix to the above code so the category list will display the full list of categories (rather than just those that have posts).
Change the following line:
<?php wp_dropdown_categories ('name=category_id'); ?>
to:
<?php wp_dropdown_categories ('hierarchical=1&hide_empty=0&name=category_id'); ?>
Forum: Plugins
In reply to: [Plugin: NextGEN Gallery] Album thumbnail link to post, not pagemor10,
I have made much more progress on this topic, so I thought I would post the info here. Firstly, to show a dropdown of the posts, add the following function to the bottom of the “plugins/nextgen-gallery/admin/functions.php” file, just before the closing “?>”:/** * {@internal Missing Short Description}} * * @since unknown * * @param unknown_type $default * @return unknown */ 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 "\n\t<option class='level-0' value='$item->ID'$current> " . esc_html($item->post_title) . "</option>"; } } else { return false; } }
Then, in the “plugins/nextgen-gallery/admin/manage-images.php” file, change the line:
<?php parent_dropdown($gallery->pageid); ?>
to:
<?php ngg_dropdown_posts($gallery->pageid); ?>
This gives you a drop-down list of the posts that are NOT trash, and works just as the page link would.
Also, if you want to have an option to create a post as well with a selectable category option, then again in the “plugins/nextgen-gallery/admin/manage-images.php” file, change the following code:
<?php if(current_user_can("publish_pages")) : ?> <tr> <th align="left"> </th> <th align="left"> </th> <th align="right"><?php _e('Create new page', 'nggallery') ?>:</th> <th align="left"> <select name="parent_id" style="width:95%"> <option value="0"><?php _e ('Main page (No parent)', 'nggallery'); ?></option> <?php parent_dropdown (); ?> </select> <input class="button-secondary action" type="submit" name="addnewpage" value="<?php _e ('Add page', 'nggallery'); ?>" id="group"/> </th> </tr> <?php endif; ?>
to:
<?php if(current_user_can("publish_posts")) : ?> <tr> <th align="left"> </th> <th align="left"> </th> <th align="right"><?php _e('Create new post', 'nggallery') ?>:</th> <th align="left"> <?php wp_dropdown_categories ('name=category_id'); ?> <input class="button-secondary action" type="submit" name="addnewpost" value="<?php _e ('Add post', 'nggallery'); ?>" id="group"/></th> </tr> <?php endif; ?>
and in the “plugins/nextgen-gallery/admin/manage.php” file, add the following code after the
if (isset ($_POST['addnewpage'])) {
if block:if (isset ($_POST['addnewpost'])) { // Add a new post check_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 post global $user_ID; $post['post_type'] = 'post'; $post['post_content'] = '[nggallery id=' . $this->gid . ']'; $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 . ' -> <strong>' . $gallery_title . '</strong> ' .__('created','nggallery') ); } }