WordPress.org

Forums

Image Gallery With Pagination (14 posts)

  1. TnExperts
    Member
    Posted 1 year ago #

    Hi guys,

    does anyone know a plugin that create galleries with pagination ?

    here is some examples :
    #1 : http://listcovery.com/20-best-of-friends-with-benefits-quotes/
    #2 : http://funnie.st/399456/celebs-ugly-feet/
    #3 : http://epicdpic.com/funny/gaming-logic-best/

    It does not matter if it's payed or free :)

    Thanks

  2. It does not matter if it's payed or free :)

    It matters here. ;)

    Have you looked at the large assortment of gallery plugins?

    http://wordpress.org/plugins/search.php?q=gallery

    In the first link that looks like a paginated post and you don't need a plugin for that.

    https://codex.wordpress.org/Pagination

  3. Marc
    Member
    Posted 11 months ago #

    Hi guys. I'm not sure if anyone of you guys manged to resolve this. I do have a solution for this.

    Here is what i have done:
    First created the gallery on the specific page in the wordpress backend. Then in my functions.php file i added the following code:

    /*FILTER: GALLERY:  --------------------------------------------------------------*/
    add_filter('post_gallery', 'filter_gallery', 10, 2);
    function filter_gallery($output, $attr)
    {
        global $post;
    
    	//GALLERY SETUP STARTS HERE----------------------------------------//
        if (isset($attr['orderby'])) {
            $attr['orderby'] = sanitize_sql_orderby($attr['orderby']);
            if (!$attr['orderby'])
                unset($attr['orderby']);
        }
    	//print_r($attr);
        extract(shortcode_atts(array(
            'order' => 'ASC',
            'orderby' => 'menu_order ID',
            'id' => $post->ID,
            'itemtag' => 'dl',
            'icontag' => 'dt',
            'captiontag' => 'dd',
            'columns' => 3,
            'size' => 'thumbnail',
            'include' => '',
            'exclude' => ''
        ), $attr));
    
        $id = intval($id);
        if ('RAND' == $order) $orderby = 'none';
    
        if (!empty($include)) {
            $include = preg_replace('/[^0-9,]+/', '', $include);
            $_attachments = get_posts(array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
    
            $attachments = array();
            foreach ($_attachments as $key => $val) {
                $attachments[$val->ID] = $_attachments[$key];
            }
        }
        if (empty($attachments)) return '';
    	//GALLERY SETUP END HERE------------------------------------------//
    
    	//PAGINATION SETUP START HERE-------------------------------------//
    	$current = (get_query_var('paged')) ? get_query_var( 'paged' ) : 1;
    	$per_page = 24;
    	//$offset = ($page-1) * $per_page;
    	$offset = ($current-1) * $per_page;
    	$big = 999999999; // need an unlikely integer
    
    	$total = sizeof($attachments);
    	$total_pages = round($total/$per_page);
    	if($total_pages < ($total/$per_page))
    	{	$total_pages = $total_pages+1;
    	}
    	//PAGINATION SETUP END HERE-------------------------------------//
    
    	//GALLERY OUTPUT START HERE---------------------------------------//
        $output = "<div class=\"gallery-images\">\n";
    	$counter = 0;
    	$pos = 0;
        foreach ($attachments as $id => $attachment)
    	{	$pos++;
            //$img = wp_get_attachment_image_src($id, 'medium');
    		//$img = wp_get_attachment_image_src($id, 'thumbnail');
            //$img = wp_get_attachment_image_src($id, 'full');	
    
    		if(($counter < $per_page)&&($pos > $offset))
    		{	$counter++;
    			$largetitle = get_the_title($attachment->ID);
    			$largeimg = wp_get_attachment_image_src($id, 'large');
    			$img = wp_get_attachment_image_src($id, array(100,100));
    			$output .= " <a href="{$largeimg[0]}" title="{$largetitle}"><img src=\"{$img[0]}\" width=\"{$img[1]}\" height=\"{$img[2]}\" alt=\"\" /></a>\n";
    		}
    
        }
        $output .= "<div class=\"clear\"></div>\n";
        $output .= "</div>\n";
    	//GALLERY OUTPUT ENDS HERE---------------------------------------//
    
    	//PAGINATION OUTPUT START HERE-------------------------------------//
    	$output .= paginate_links( array(
    		'base' => str_replace($big,'%#%',esc_url(get_pagenum_link($big))),
    		'format' => '?paged=%#%',
    		'current' => $current,
    		'total' => $total_pages,
    		'prev_text'    => __('«'),
    		'next_text'    => __('»')
    	) );
    	//PAGINATION OUTPUT ENDS HERE-------------------------------------//
    
        return $output;
    }
    /*FILTER: GALLERY:  --------------------------------------------------------------*/

    The nice thing is that you dont need to use a third part plugin. Hope this helps

  4. Grubbi
    Member
    Posted 11 months ago #

    If I add this code to my functions.php file found in wp-includes then my site disappears...blank white pages.

    Is there anything I need to do to make the code work, or any specific place I need to put it in the functions.php file? Thanks

  5. alchymyth
    Forum Moderator
    Posted 11 months ago #

    If I add this code to my functions.php file found in wp-includes

    don't edit any files in the /wp-includes/ folder

    -

    the code belongs into functions.php of your currently used theme /wp-content/themes/your-theme/functions.php

  6. Francesco
    Member
    Posted 11 months ago #

    I've added the piece of code to my child theme's functions.php, but i get a blank admin page, and a blank page on the website.

    has anyone else tested this code?

    cheers

  7. esmi
    Forum Moderator
    Posted 11 months ago #

    If you require assistance then, as per the Forum Welcome, please post your own topic instead of tagging onto someone else's topic.

  8. Francesco
    Member
    Posted 11 months ago #

    why do i have to open a new topic, if my question is related to this very topic?

  9. Andrew
    Forum moderator
    Posted 11 months ago #

    It really does benefit you if you create a new topic, please take on that advice.

  10. esmi
    Forum Moderator
    Posted 11 months ago #

    These forums have guidelines. Please read them. As you will see, one of these guidelines - entitled Where to Post - specifically states:

    Unless you are using the same version of WordPress on the same physical server hosted by the same hosts with the same plugins, theme & configurations as the original poster, do not post in someone else's thread. Start your own topic.

    Please abide by this.

  11. Francesco
    Member
    Posted 10 months ago #

    allright, sorry if i've messed up this topic.

    FYI i've opened a new one here: http://wordpress.org/support/topic/gallery-pagination-2?replies=1

  12. elbego
    Member
    Posted 6 months ago #

    Error in line 495, change to :

    $output .= '<a href='.$largeimg[0].' title='.$largetitle.'><img src='.$img[0].' width='.$img[1].' height='.$img[2].' 	/></a>';

    Works good!

  13. elbego
    Member
    Posted 6 months ago #

    Better (with lightbox pop=up images) :

    $output .= '<a rel="lightbox" href='.$largeimg[0].' title='.$largetitle.'><img src='.$img[0].' width='.$img[1].' height='.$img[2].' 	/></a>';

Topic Closed

This topic has been closed to new replies.

About this Topic