WordPress.org

Forums

Custom Field Template
Unable to insert NextGen Gallery into textarea field (26 posts)

  1. JHouse
    Member
    Posted 4 years ago #

    Hi,

    While I can select one of the galleries just fine from NextGen, it won't insert the shortcode into the Custom Fields Template textarea. How do I get this to work properly?

    Also, is there a way where this will work with regular fields, so the user can click on NextGen, select the desired gallery, and pow, it inserts the shortcode into a basic text field, thus not a textarea field?

    Thanks for an awesome plugin.

  2. JHouse
    Member
    Posted 4 years ago #

    Okay, I just learned that the shortcode is being inserted, however, it's inserting into the main text area up top, thus not in the custom fields. Any idea on how to fix this?

    Thanks.

  3. proximity2008
    Member
    Posted 4 years ago #

    Hi there,

    I have done something similar with NextGen and the CFT.

    I used a select drop down that grabs the NextGen Gallery data. This code is from a previous project I worked on, I'll share it with you:

    Template:

    [gallery]
    hideKey = true
    label = Select Gallery for this page. <br /> <a href=/wp-admin/admin.php?page=nggallery-manage-gallery>Click here</a> to modify the order of your gallery.
    type = select
    code = 0'

    Code Block 0

    global $wpdb;
    	$values = array();
    	$attachments = $wpdb->get_results('SELECT gid,title,path FROM wp_ngg_gallery');
    	foreach ($attachments as $attachment) {
    	$str = '[' . $attachment->gid . ']----->'.$attachment->title .'<-----!!' .$attachment->path . '!!';
    	$values[] = $str;
    	 }

    That will make a drop down containing the gallery id [id] the name of the gallery and the !!path!! to the gallery folder. I put them in delimeters so as to be able to extract them in the template. I think I needed both !!path!! and [id] to get it working. You can adjust the $str to how you want it displayed to your editor.

    You may just want to have the shortcode [nggallery id=x] being used in the field. That edit will be easy to make:

    $str = '[ngggallery id=' . $attachment->gid . ']';

    In you template you will just have to apply filters on that custom field that you've made so it outputs the gallery.

    In your template:

    <?php
    $unprocessedfield = get_post_meta($post->ID, 'nameofyourcustomfield',true);
    $processedfield = apply_filters('the_content', $unprocessedfield );
    echo $processedfield;
    ?>

    That should get you moving in the right direction.

  4. JHouse
    Member
    Posted 4 years ago #

    Wow, thanks for all your help.

    I implemented the code you pasted, unaltered (not sure if I was supposed to change any values) and I'm getting part of it to work. The drop menu appears, but none of the gallery options. I tried placing the your code in the Magic Fields admin template part. Am I supposed to alter it and/or place it elsewhere?

    I really appreciate your efforts and time here. Seriously. That's way cool of you.

    Peace.

  5. proximity2008
    Member
    Posted 4 years ago #

    Hi,

    If the gallery drop down is empty, perhaps the code block code is wrong.
    First of all I can spot an error with the first part of the template code:

    [gallery]
    hideKey = true
    label = Select Gallery for this page. <br /> <a href=/wp-admin/admin.php?page=nggallery-manage-gallery>Click here</a> to modify the order of your gallery.
    type = select
    code = 0

    The other code block needs to go into the PHP Code Experimental Option section (not in the same template block). This code works for an older installation of NextGen 1.5

    global $wpdb;
    	$values = array();
    	$attachments = $wpdb->get_results('SELECT gid,title,path FROM wp_ngg_gallery');
    	foreach ($attachments as $attachment) {
    	$str = '[ngggallery id=' . $attachment->gid . ']';
     $values[] = $str;
    }

    Does that work?

  6. JHouse
    Member
    Posted 4 years ago #

    Hmmm, I did as suggested, but no dice.

    I copied the first chunk of code and placed it in the Custom Fields Template per your suggestion, then copied the other code block and pasted it into the PHP Code Experimental Option section. Unfortunately, the dropdown menu still comes up empty. I'm using the latest NextGen Gallery, as well as WP.

    Thanks again for your help.

  7. proximity2008
    Member
    Posted 4 years ago #

    Ok,

    The code does work, I've tested it.
    How are you storing your images? In NextGen galleries I hope because this outputs complete galleries.

  8. JHouse
    Member
    Posted 4 years ago #

    Yep, in NextGen galleries. You know what though, I've been playing with the Magic Fields plugin and it's really doing everything I want. I may just abort this CFT mission.

    That said, I really don't want to waste your time. Thanks for your consistent efforts. Seriously. Much appreciated.

  9. JHouse
    Member
    Posted 4 years ago #

    One last thing...do you think running php4 has anything to do with the issue? I'm pretty sure that's what my host is running.

  10. proximity2008
    Member
    Posted 4 years ago #

    No it will work with php4, but I'd move host php 4 is really old!

    Yeah I have heard good things with Magic Fields but I've stuck with CFT.

    A shame that we couldn't sort this issue out.

  11. JHouse
    Member
    Posted 4 years ago #

    Hey, I'm still down to sort it out if you are. I'd like to have a good competitive custom fields' program in the event Magic Fields go awry or something. Nice to have backup.

    So yeah, got any other ideas as to what may be the problem? I'll keep testing.

    Thanks.

  12. proximity2008
    Member
    Posted 4 years ago #

    Try this code in a php template.

    <?php
    	global $wpdb;
    	$values = array();
    	$attachments = $wpdb->get_results('SELECT * FROM wp_ngg_gallery');
    
    	echo '<pre>';
    	echo 'query results: ' . print_r($attachments);
    	$wpdb->print_error();
    	echo '</pre>';	
    
    	foreach ($attachments as $attachment) {
    		$str = '[ngggallery id=' . $attachment->gid . ']';
     	$values[] = $str;
    	}
    
    	echo '<pre>';
    	echo '$values: ' . print_r($values);
    	echo '</pre>';
    ?>
  13. JHouse
    Member
    Posted 4 years ago #

    This is the error I get:

    Parse error: syntax error, unexpected '<' in /home/xxxxxx/public_html/wp-content/plugins/custom-field-template/custom-field-template.php(1691) : eval()'d code on line 1

    I only get this error when I couple your latest code above (placed in the PHP CODE area) this code in the Template content area:

    [gallery]
    hideKey = true
    label = Select Gallery for this page. <br /> <a href=/wp-admin/admin.php?page=nggallery-manage-gallery>Click here</a> to modify the order of your gallery.
    type = select
    code = 0

    As of now, those are the only two sections of code I'm using. Well, code that I received from you. Not sure if I'm supposed to combine them with some of your other code above or anything.

    Thanks for the continued help.

  14. proximity2008
    Member
    Posted 4 years ago #

    Hi again,

    Sorry should've been more clear. The last code submitted is a test. You should put it on a page (page.php) and then load that page in your browser.

    The output will help to see where things are not working.

    Thanks.

  15. JHouse
    Member
    Posted 4 years ago #

    This crossed my mind yesterday...since I'm already totally locked on Magic Fields and thus don't see myself using CFT anymore (although it's a cool plugin), and since you already have it working on your host, I guess I don't see a reason to get this working on my set up anymore given that I highly doubt I'll use it now or in the future.

    That said, I really don't want to waste your time any further. I'm well aware that I stated I would stick around 'till we sort it out, but is it productive time spent for either of us? You know what I mean? If, however, you want to be able to test your code out for whatever reason and get this to work, I'll stay around and test it out.

    Anyways, I totally respect and appreciate your time. Much much appreciated. You were very consistent with your support.

    Take care man.

  16. dereknorrbom
    Member
    Posted 4 years ago #

    Hi proximity2008,

    no idea if this will get to you but i am trying to do something similar. I want to populate a select box (drop down) using CFT's "experimental php code" with a array of bundles as the valuelabel, and an array of sku's of the bundles as the value. Im still learning when it comes to php so any help is super appreciated.

    Basically i have a db table called bn_bundles, and in that table is a column called bundle, and a column called sku. I just dont know how to plug that into something that CFT could use.

    The idea is someone can select from a drop down which bundle they want to display.
    They are presented with the bundle names to choose from, but the value i want to pass to the page is the sku.

    Thank you for taking time to read this.

  17. dereknorrbom
    Member
    Posted 4 years ago #

    actually i think i got something working. Might have answered my own question, this appears to be working.

    global $wpdb;
    	$values = array();
            $valueLabel = array();
    	$attachments = $wpdb->get_results('select * from bn_bundles order by bundle asc');
    	foreach ($attachments as $attachment) {
    	$str = '[' . $attachment->bundle . ']';
            $str2 = '[' . $attachment->sku . ']';
    	$values[] = $str ;
            $valueLabel[] = $str2 ;
     }
  18. pelicanj
    Member
    Posted 4 years ago #

    Sorry to rain on people parade but I believe I have found a much more simple solution.

    Go to the tinymce.js file and replace line 68 window.tinyMCE.execInstanceCommand('content', 'mceInsertContent', false, tagtext);

    with

    tinyMCEPopup.editor.execCommand('mceInsertContent', false, tagtext);

  19. adam533
    Member
    Posted 4 years ago #

    @proximity2008

    Sorry to bump an old thread but was hoping you could help me. I have used the code you supplied and it seemed to be working. When I check the page on the site though, all I see is the value that appears in the dropdown menu instead of the actual gallery. Could you possibly help me to get the actual gallery to display on the page?

    I am working on a project now where this would be a huge help. I never even thought of this as an option but now that I see it is possible, I would love to get it to work.

    (Hopefully you see this! :)

  20. proximity2008
    Member
    Posted 4 years ago #

    Hey Adam,

    It's good that you have the number being output, you are almost done.

    What has to happen now is that WordPress needs to recognise that value as standing for a gallery id. NextGen uses a shortcode to do this, so you'll need to run the_content filter on that ID.

    Now I haven't used NextGen for ages but as per above the shortcode is: [ngggallery id="X"] where X is the ID of the NextGen Gallery.

    In your templte file somewhere:

    <?php
    $cft_id = get_post_meta( $post->ID, 'gallery', true );
    echo apply_filters( "the_content" , "[ngggallery id='{$cft_id}']" );
    ?>

    That should output the gallery I think.

  21. adam533
    Member
    Posted 4 years ago #

    The code I am using in the PHP Code section of CFT is:

    global $wpdb;
    	$values = array();
    	$attachments = $wpdb->get_results('SELECT gid,title,path FROM wp_ngg_gallery');
    	foreach ($attachments as $attachment) {
    	$str = '[ngggallery id=' . $attachment->gid . ']';
     $values[] = $str;
    }

    The code in my page template is what you just pasted above:

    <?php
    $cft_id = get_post_meta( $post->ID, 'gallery', true );
    echo apply_filters( "the_content" , "[ngggallery id='{$cft_id}']" );
    ?>

    When I do that the result I get on my page is:
    [ngggallery id='[ngggallery id=1]‘]

  22. proximity2008
    Member
    Posted 4 years ago #

    Easy fix:

    <?php
    $cft_id = get_post_meta( $post->ID, 'gallery', true );
    echo apply_filters( "the_content" , "{$cft_id}" );
    ?>
  23. adam533
    Member
    Posted 4 years ago #

    So close... :)

    It is showing the correct code now:
    [ngggallery id=1]

    Though WordPress is wrapping that in paragraph tags, so instead of showing the gallery it is showing the code. Can I eliminate the paragraph tags?

    Thank you so much for your quick help on this.

  24. proximity2008
    Member
    Posted 4 years ago #

    I've spotted it now. There is a typo back in your CFT Php code section.

    See the tripple g in ngggallery.

    global $wpdb;
    	$values = array();
    	$attachments = $wpdb->get_results('SELECT gid,title,path FROM wp_ngg_gallery');
    	foreach ($attachments as $attachment) {
    	$str = '[nggallery id=' . $attachment->gid . ']';
     $values[] = $str;
    }
  25. adam533
    Member
    Posted 4 years ago #

    Edit: Wait I just went back and changed the php code template to the previous version we used and it works now. Thank you very much for your help on solving this.

    The code that works, for anybody that wants to do this themselves is:

    This goes in your page template:

    <?php
    $cft_id = get_post_meta( $post->ID, 'gallery', true );
    echo apply_filters( "the_content" , "[nggallery id='{$cft_id}']" );
    ?>

    This goes in the PHP Code Section of Custom Field Template:

    global $wpdb;
    	$values = array();
    	$attachments = $wpdb->get_results('SELECT gid,title,path FROM wp_ngg_gallery');
    	foreach ($attachments as $attachment) {
    	$str = '[nggallery id=' . $attachment->gid . ']';
     $values[] = $str;
    }

    This goes in the Custom Field Template Options:

    [gallery]
    hideKey = true
    label = Select Gallery for this page.
    type = select
    code = 0

    Thanks again for your help!

  26. Chris
    Member
    Posted 4 years ago #

    FYI when I implemented the code above it displayed an extra parenthesis and a bracket underneath the photos like such: ']

    To get rid of it I just modified the php code in the template to look like this:

    <?php
    $cft_id = get_post_meta( $post->ID, 'gallery', true );
    echo apply_filters( "the_content" , "[nggallery id={$cft_id}" );
    ?>

    I simply removed the closing bracket and parenthesis at the very end of the code. Not sure if this is compliant but it works.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Custom Field Template
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic