{"id":651,"date":"2008-09-26T23:59:27","date_gmt":"2008-09-26T21:59:27","guid":{"rendered":"http:\/\/www.ikiru.ch\/blog\/?p=651"},"modified":"2024-05-27T07:55:15","modified_gmt":"2024-05-27T12:55:15","slug":"how-to-add-a-search-function-for-nextgen-gallery-wordpress-plugin","status":"publish","type":"post","link":"https:\/\/www.jcvignoli.com\/blog\/en\/2008\/how-to-add-a-search-function-for-nextgen-gallery-wordpress-plugin","title":{"rendered":"How to add a search function to NextGen gallery wordpress plugin"},"content":{"rendered":"\n<p><a href=\"http:\/\/alexrabe.boelinger.com\/wordpress-plugins\/nextgen-gallery\/\">NextGen gallery<\/a> is quite a nice plugin. But it lacks a function, a very obvious one&#8230; the possibility to search inside the pictures name, alternative text or description. Wouldn&rsquo;t be nice if you can, with only one search query, display pictures from your gallery matching the searching terms, as well as you posts?<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"https:\/\/www.jcvignoli.com\/blog\/wp-content\/uploads\/wp-plugin-ngg-search.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"500\" src=\"https:\/\/www.jcvignoli.com\/blog\/wp-content\/uploads\/wp-plugin-ngg-search.jpg\" alt=\"wp plugin nextgen gallery search\" class=\"wp-image-2085\" srcset=\"https:\/\/www.jcvignoli.com\/blog\/wp-content\/uploads\/wp-plugin-ngg-search.jpg 1024w, https:\/\/www.jcvignoli.com\/blog\/wp-content\/uploads\/wp-plugin-ngg-search-300x146.jpg 300w, https:\/\/www.jcvignoli.com\/blog\/wp-content\/uploads\/wp-plugin-ngg-search-768x375.jpg 768w, https:\/\/www.jcvignoli.com\/blog\/wp-content\/uploads\/wp-plugin-ngg-search-150x73.jpg 150w, https:\/\/www.jcvignoli.com\/blog\/wp-content\/uploads\/wp-plugin-ngg-search-200x98.jpg 200w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n<\/div>\n\n\n<p class=\"has-text-align-center\"><\/p>\n\n\n\n<p>I&rsquo;m not a coder. Not at all. But it still works like a charm. If you know how to edit you theme, here are the modifications you have to go through:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Add this <a href=\"\/blog\/wp-content\/files\/wordpress-nggplugin-search-call.txt\">code<\/a> in your file search.php (inside your template folder), right after<br \/><code>&lt;h2 class=\"pagetitle\">Search Results&lt;\/h2><\/code><br \/>or somewhere (depending your template) after<br \/>&lt;?php if (have_posts()) : ?>,<br \/>otherwise it wouldn&rsquo;t find the pictures. Pay a special attention to the line<br \/><code>$nggpictures = ngg_get_search_pictures($keywords, '');<\/code><br \/>since on the second function argument ( \u00a0\u00bb ) you may indicate the number of pictures you want to display on each row result. IE, if you want to get 6 pictures displayed on each row, you have to change the line to<br \/><code>$nggpictures = ngg_get_search_pictures($keywords, '6');<\/code><br \/>By default, 4 pictures for each row are displayed. Note that you may also split the code, and put a part before and another part after the &lt;?php while [&#8230;] ?> function with the result to display pictures (if relevent) even if there is no post. That&rsquo;s a bit more advanced, but people with advanced php skills won&rsquo;t need any complementary explanation to achieve that.<\/li>\n\n\n\n<li>Add this <a href=\"\/blog\/wp-content\/files\/wordpress-nggplugin-search-function.txt\">code<\/a> (or this <a href=\"\/blog\/wp-content\/files\/wordpress-nggplugin-search-function2.7.txt\">code<\/a> if you use NexGen 1.0) anywhere in your file functions.php (inside your template folder, create one if you don&rsquo;t have any)<\/li>\n<\/ol>\n\n\n\n<p>That&rsquo;s all ! Have a look to my searchbar, and see how it works. Try with \u00ab\u00a0jim lobe\u00a0\u00bb or <a href=\"\/blog\/index.php?s=jim+lobe\">click here<\/a>.<\/p>\n<div class=\"pld-like-dislike-wrap pld-template-1\">\r\n    <div class=\"pld-like-wrap  pld-common-wrap\">\r\n    <a href=\"javascript:void(0)\" class=\"pld-like-trigger pld-like-dislike-trigger  \" title=\"Super article!\" data-post-id=\"651\" data-trigger-type=\"like\" data-restriction=\"cookie\" data-already-liked=\"0\">\r\n                        <i class=\"fas fa-thumbs-up\"><\/i>\r\n                <\/a>\r\n    <span class=\"pld-like-count-wrap pld-count-wrap\">0    <\/span>\r\n<\/div><div class=\"pld-dislike-wrap  pld-common-wrap\">\r\n    <a href=\"javascript:void(0)\" class=\"pld-dislike-trigger pld-like-dislike-trigger  \" title=\"Pas terrible...\" data-post-id=\"651\" data-trigger-type=\"dislike\" data-restriction=\"cookie\" data-already-liked=\"0\">\r\n                        <i class=\"fas fa-thumbs-down\"><\/i>\r\n                <\/a>\r\n    <span class=\"pld-dislike-count-wrap pld-count-wrap\">0<\/span>\r\n<\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>NextGen gallery is quite a nice plugin. But it lacks a function, a very obvious one&#8230; the possibility to search inside the pictures name, alternative text or description. Wouldn&rsquo;t be nice if you can, with only one search query, display pictures from your gallery matching the searching terms, as well as you posts? I&rsquo;m not [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":5299,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"","ocean_second_sidebar":"","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"","ocean_custom_header_template":"","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"","ocean_menu_typo_font_family":"","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"","ocean_post_oembed":"","ocean_post_self_hosted_media":"","ocean_post_video_embed":"","ocean_link_format":"","ocean_link_format_target":"self","ocean_quote_format":"","ocean_quote_format_link":"post","ocean_gallery_link_images":"on","ocean_gallery_id":[],"footnotes":""},"categories":[4623,4621,4625],"tags":[34578,34581,34584,34587,34590],"class_list":["post-651","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog-en","category-computers","category-wordpress-en","tag-gallery-en","tag-nextgen-gallery-en","tag-plugin-en","tag-search-en","tag-wordpress-en","entry","has-media"],"aioseo_notices":[],"language":"en","_links":{"self":[{"href":"https:\/\/www.jcvignoli.com\/blog\/wp-json\/wp\/v2\/posts\/651","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jcvignoli.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jcvignoli.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jcvignoli.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jcvignoli.com\/blog\/wp-json\/wp\/v2\/comments?post=651"}],"version-history":[{"count":2,"href":"https:\/\/www.jcvignoli.com\/blog\/wp-json\/wp\/v2\/posts\/651\/revisions"}],"predecessor-version":[{"id":6559,"href":"https:\/\/www.jcvignoli.com\/blog\/wp-json\/wp\/v2\/posts\/651\/revisions\/6559"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.jcvignoli.com\/blog\/wp-json\/wp\/v2\/media\/5299"}],"wp:attachment":[{"href":"https:\/\/www.jcvignoli.com\/blog\/wp-json\/wp\/v2\/media?parent=651"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jcvignoli.com\/blog\/wp-json\/wp\/v2\/categories?post=651"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jcvignoli.com\/blog\/wp-json\/wp\/v2\/tags?post=651"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}