• I would like to share my code example, which works on my site.
    My code is based on the example in the plugin themes folder, it is not perfect as I still haven’t figured out how to display pagination on album page, so if anyone got more ideas or found fault in it, please kindly point it out, it would be much appreciated.

    Please also check the data variable available in the fb api which the plugin is using
    https://developers.facebook.com/docs/graph-api/reference/v2.2/album
    https://developers.facebook.com/docs/graph-api/reference/v2.2/album/photos

    Here is the code on my gallery page
    ———————————————————————————————–

    <?php
    /*
     * Template Name: gallery page
     */
    ?>
    <?php
        get_header();
    ?>
    
    <!-- here will be the other html code with your own structure-->
    
    <!-- the below is a switch to display whether album list page or the photo list in a album-->
    <div id="content" class="gallery" role="main">
    <?php
    				if (!empty($_GET['id'])) {
    					// Photo List
    					theme_show_photos($_GET['id']);
    				}
    				else {
    					// Album List
    					theme_show_albums();
    				}
    				?>
    </div>
    
    <?php get_footer(); ?>
    
    <!-- below is the function for calling the fb album data from the plugin -->
    <?php
    /**
     * Render the album list
     */
    function theme_show_albums() {
    //
    // Get Album List
    //
    $list = facebook_page_albums_get_album_list(array(
    	'per_page' => 99
    //as pagination is not working of album listing page in my code, this "99" will allow all the albums are showing on the first page
    ));
    if (empty($list)) :
    	?>
    	<p>
    		No album found
    	</p>
    <?php
    	return;
    endif;
    ?>
    
    <ol class="album-list">
    	<?php
    	//
    	// Loop Album List and Render items
    	//
    	if (!empty($list)) : foreach ($list as $item) :
    		if ($item['type'] != 'normal' || $item['name'] == 'Cover Photos') {
    			continue;
    		}
    
    		// Link to each album
    		$link = add_query_arg('id', $item['id']);
    
    		?>
    	<?php if (!empty($item['cover_photo_data'])):
    // avoid empty album
          ?>
    		<li class="album">
    			<a href="<?php echo $link;?>" class="" target="_blank">
    			<?php
    			// It has a thumbnail
    			if ($thumb = $item['cover_photo_data']):?>
    				<div class="album">
    						<div class="" style="background: url('<?php echo $thumb['source'];?>') 50% 50% no-repeat;"></div>
    				</div>
    			<?php endif; ?>
    			<div class="album-info">
    				<div class=""><?php echo $item['name'];?></div>
    				<div class="">
    					<?php if (!empty($item['comments'])) :?>
    						<div class="">Comments: <?php echo $item['comments'];?></div>
    					<?php endif;?>
    					<?php if (!empty($item['likes'])) :?>
    						<div class="">Like: <div class="like-txt"><?php echo $item['likes'];?></div></div>
    					<?php endif;?>
    				</div>
    			</div>
    			</a>
    		</li>
    			<?php endif;?>
    	<?php endforeach; endif;?>
    </ol>
    <?php
    }
    
    /**
     * Render the photo list
     *
     * @param Integer
     */
    function theme_show_photos($id) {
    	global $paged;
    
    	$per_page = 30;
    	if (empty($paged)) $paged = 1;
    
    	// Album Information
    	if (!$album = facebook_page_albums_get_album($id)) {
    		echo 'failed to get album information';
    		return false;
    	}
    
    	//
    	// Photo List
    	//
    	if (!$list2 = facebook_page_albums_get_photo_list($id, array(
    		'per_page' => $per_page,
    		'paged'    => $paged
    	))) {
    		echo 'failed to get photo list';
    		return;
    	}
    	?>
    	<div class=""><a href="<?php echo home_url(); ?>/gallery" target="_self" title="Back to Gallery">Back to Gallery</a></div>
    	<div class="photo-list-header">
    		<h3><?php echo $album['name'];?></h3>
    		<div class="counts">
    			<a class="goto-facebook" href="<?php echo $album['link'];?>" target="_blank" title="See on Facebook">See on Facebook</a>
    		</div>
    	<ol class="photo-list">
    		<?php if (!empty($list2)): foreach ($list2 as $itemf):?>
    			<li class="photo">
    				<a class="photo-link" href="<?php echo $itemf['source'];?>" title="<?php if (!empty($itemf['name'])) echo $itemf['name'];?>">
    				<div class="photo-thumb">
    					<div class="" style="background: url('<?php echo $itemf['source'];?>') 50% 50% no-repeat;"></div>
    				</div>
    				<div class="photo-info">
    					<div class=""><?php if (!empty($itemf['message'])) echo $itemf['message'];?></div>
    					<div class="">
    						<?php if (!empty($itemf['likes'])) :?>
    							<div class="l">Like: <?php echo count($itemf['likes']['data']);?></div>
    						<?php endif;?>
    					</div>
    				</div>
    				</a>
    			</li>
    		<?php endforeach; endif;?>
    	</ol>
    	<div class="page-control">
    		<?php
    		//
    		// Page Control
    		//
    		echo paginate_links( array(
    			'base' => add_query_arg( 'paged', '%#%' ),
    			'format' => '',
    			'total' => ceil($album['count'] / $per_page),
    			'current' => $paged,
    			'prev_text' => '&laquo;',
    			'next_text' => '&raquo;',
    			'mid_size' => 5
    		));
    		?>
    	</div>
    <?php
    	return true;
    }
    ?>

    https://wordpress.org/plugins/facebook-page-albums/

  • The topic ‘code example sharing (php 5.4.4, wordpress 4.2.2 and Facebook Page Albums 3.0)’ is closed to new replies.