• I want the thumbnails that appear when you are in an album featuring multiple galleries to point to a post rather than a page. At present in the Gallery Settings the “Page link to:” option only allows the gallery thumbnail to link to a page. There is no reason for this restricition and I’m hoping someone has found a way around it.

    I think it could be solved by finding the code that generates the drop-down menu in the Gallery Settings page so that it includes posts as well as pages but try as I might I can’t find this code in the plugin files.

    Any help would be much appreciated.

Viewing 13 replies - 1 through 13 (of 13 total)
  • Found it. Took ages, but that’s because I was searching for “Page Link to:”. It actually appears in the code without the colon.

    It’s in Nexgen-gallery->admin->manage-images.php
    on or about line 215

    Best of luck,
    JA <-off on my own search to figure out how to display two albums side-by-side

    @jageo Thanks, I actually found that myself too. Unfortunately it took me no closer to fixing the problem: As far as I can tell the drop-down list is created by this line of code:

    <?php parent_dropdown($gallery->pageid); ?>

    But I can’t figure out how to change it to make it show posts instead of pages. Simply switching the last part to “postid” for example just broke it. Anyone with more php skill than me (or a reference guide for NextGen) want to give this one a whirl?

    Hah! I found an alternate solution: Just replace the entire drop-down menu with a simple text input field. True, I now have to manually find the ID for the target post, but it works perfectly.

    So, for those of you playing along, in NextGen-gallery/admin/manage-images.php delete the following lines of code:

    <select name="pageid" style="width:95%">
    <option value="0" ><?php _e('Not linked', 'nggallery') ?></option>
    <?php parent_dropdown($gallery->pageid); ?>
    </select>

    … and replace them with this:

    <input name="pageid" type="text" />

    Quod Erat Demonstrandum

    *Big thanks to jageo for putting me on the right track*

    mor10,
    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">&nbsp;</th>
    					<th align="left">&nbsp;</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">&nbsp;</th>
    					<th align="left">&nbsp;</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') );
    			}
    		}

    Here 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'); ?>

    Works great, thanks!

    Is there a way to limit the posts displayed in “page link to” to just a single category? Displaying all posts available in the blog is just very dificult to manage.

    Doesnt work for me: no post is created or linked

    jtovar

    (@jtovar)

    Any way this can be applied to allowing for a custom URL instead of internal WordPress posts/pages? Pretty please?

    Bravo, carlbenton! Wow, nice mod. Shame that this can’t be rolled into the source of NextGen, for when the plugin is updated, these changes will be lost.

    This works great, however, When a change is made in the gallery the link is destroyed. How can this be fixed?

    Speggey, can you define “change”? Like, an update to the NextGen plugin? I wouldn’t think that such an update would kill the link, since it’s a MySQL entry.

    By change I mean, make a change in the images or the name or something in the gallery. Solved it though.

    delete rownumber: 374-375 in manage.php

    if ( nggGallery::current_user_can( 'NextGEN Edit gallery page id' ))
    $wpdb->query( $wpdb->prepare ("UPDATE $wpdb->nggallery SET pageid= '%d' WHERE gid = %d", (int) $_POST['pageid'], $this->gid) );

    Otherwise it will override the linked page id on save.

    Speggey, this is strange. I’m not seeing the problem you describe. When I make other gallery changes, my post ID link is holding.

    carlbenton, how hard would it be to add a category dropdown which would would limit the quantity of the post dropdown? This would come in handy with a high post count.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘[Plugin: NextGEN Gallery] Album thumbnail link to post, not page’ is closed to new replies.