How-to show NextGen gallery in excerpt limit img count
-
Hello,
I am using NextGen gallery in a project for a client. The client wants to be able to add galleries to their posts/pages (no problem), but also wanted an excerpt of the gallery to show up anytime an excerpt of the post is displayed. The core WordPress functions do not recognize the NextGen gallery, and after hours of searching howto do this to no avail (maybe i just suck at searching) I decided to code a function that does this.
Here is my solution which shows excerpts of a NextGen gallery in a post/page excerpt:
in your themes function.php add:
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 );
}
}
}
`
And then inside your loop just call ngg_excerpt(); wherever you want the gallery excerpt to outputPlease note that the excerpt will show pagination links, which will be broken. I’m still trying to workout a solution to not display pagination links. Any insights are appreciated. I will post pagination solution once I figure it out…
Cheers
- The topic ‘How-to show NextGen gallery in excerpt limit img count’ is closed to new replies.