Thread Starter
redcam
(@redcam)
Also, this does not take into account that you may have other short codes in posts. If that is the case you would need to use a general expression that filters out [ngg] as opposed to [].
Nevermind, I edited the above to only grab NextGen shortcode
Thanks a lot for posting this!
would love to use this but the code above breaks the site, is there anything missing in the code above??
thanks!
Line 3 was missing a the semi-colon .. it should be
$content_data = get_the_content();
then it will work
Also to get rid of the broken image links, pagination and slideshow piece, make a new template to call in nggSHowGallery (i called mine gallery-compact.php) in which you remove the link, pagination and slideshow code.
then upload new template to ngg .. \View folder
then reference the new template in redcam’s code .. change:
echo nggShowGallery( $gallery_id, null , 4 );
to:
echo nggShowGallery( $gallery_id, “compact” , 4 );
(note you enter only “compact” bc it appears that nextgen code will parse it out eg it will recognize “compact” as “gallery-compact.php”)
also, since the links are removed the ngg-gallery-thumbnail style has a link hover that shades that thumbnail box gray .. i made new set of styles named “ngg-gallery-thumbnail-nolink” in which i removed that hover so doesn’t turn gray when mouse over : )
Thanks for the reply, however i just keep getting “[Gallery not found]” when i call ngg_excerpt(); in the loop. What could be wrong?
Here’s the code i tried from my home.php to call the function…
<?php get_header(); ?>
<div id="content" class="narrowcolumn">
<?php if (have_posts()) : ?>
<?php
while(have_posts()) : the_post(); if(!($first_post == $post->ID) && !is_sticky()) : ?>
<div class="post lastfive" id="post-<?php the_ID(); ?>">
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'chaoticsoul'), get_the_title()); ?>"><?php the_title(); ?></a></h2>
•<?php the_time(get_option("date_format")); ?> • <?php comments_popup_link(__('No Comments', 'chaoticsoul'), __('1 Comment', 'chaoticsoul'), __('% Comments', 'chaoticsoul')); ?> <?php edit_post_link(__('Edit', 'chaoticsoul'), '(', ')'); ?>
<div class="entry">
<?php ngg_excerpt(); ?>
<?php the_content("<span class=\"continue\">" . __('Continue reading', 'chaoticsoul') . " '" . the_title('', '', false) . "'</span>"); ?>
<p class="postmetadata"><?php printf(__('Posted in %s', 'chaoticsoul'), get_the_category_list(', ')); ?>
<?php the_tags('<br />' . __( 'Tags' ) . ': ', ', ', ''); ?>
</p>
<div class="splitter"> </div>
</div>
</div>
<?php endif; endwhile; ?>
and in functions.php i added the function like this:
function ngg_excerpt(){
//get the post content
$content_data = get_the_content();
//extract shortcode from content
preg_match("/\[ngg([^}]*)\]/", $content_data ,$matches);
$results = $matches[1];
//if shortcode exists in content
if (!empty($results)){
//extract gallery id from shortcode
$gallery_id = preg_replace("/[^0-9]/", '', $matches[1]);
//make sure that NextGen is loaded
if (function_exists(nggShowGallery)){
//output gallery, showing only 4 images
echo nggShowGallery( $gallery_id, null , 4 );
}
}
}
Just keep getting [Gallery Not Found] :/
It seems galleries created with [ ] / \ in their names will not work to be displayed, any solution for this?