You’re using YAPB, you want to create or use your own theme and now you’re stuck on how to create a mosaic page featuring all your photos? Thanks god – Here’s a post describing exactly that topic ;-) Basically, a mosaic page is a standard WP page using a custom page template. The job of the custom page template is to fetch all your YAPB images and to display them in some form. So: Let’s just do it:
Create a page template file
So let’s start with our new page template: Create a file named tpl.yapb.mosaic.php in your current theme folder.
Throw in some WP Metadata
As a first step we define a standard PHP comment at top with meta data so WordPress can identify this file as template:
<?php /* Template Name: YAPB Photo Mosaic Page (Prototype) */ ?>
Create some infrastructure
Now some default infrastructure for WP templates like calling the header, starting the WP loop, displaying the page title and content:
<?php
get_header(); ?>
<!-- Let's start the WordPress loop -->
<?php if (have_posts()): while (have_posts()): the_post(); ?>
<?php global $post; ?>
<div class="post">
<h1><a href="<?php echo get_permalink() ?>"><?php the_title(); ?></a></h1>
<?php the_content('read more...'); ?>
Define what you want
To display the thumbnails of all our photos, we need to know what we want to fetch exactly. In my case, i assign each photoblog post to a special category “photoblog”. That category is configured in YAPB – so i can ask for it’s id and get all (or at least the last 1000) posts of that category with a simple WordPress function. Additionally i use this php part to define the format of the thumbnails i want to display on this page:
<?php
// Let's get the last 1000 photoblog entries
$photoblog_posts = get_posts( 'category=' . get_option('yapb_default_post_category') . '&numberposts=1000' );
// Let's define the needed thumbnail format
$thumbConfig = array( 'h=80', 'q=100', 'fltr[]=usm|60|0.5|3' );
?>
Loop through the fetched posts
Since we should have all needed posts now, we simply cycle through all of them, get the image and display the thumbnails. In this sample i use a unordered list as structure for the images:
<ul>
<?php foreach($photoblog_posts as $photoblog_post): ?>
<?php if (!is_null($image = YapbImage::getInstanceFromDb($photoblog_post->ID))): ?>
<li><a title="<?php echo $photoblog_post->post_title ?>" href="<?php echo get_permalink($photoblog_post->ID) ?>"><img src="<?php echo $image->getThumbnailHref($thumbConfig) ?>" width="<?php echo $image->getThumbnailWidth($thumbConfig) ?>" height="<?php echo $image->getThumbnailHeight($thumbConfig) ?>" alt="<?php echo $photoblog_post->post_title ?>" /></a></li>
<?php endif ?>
<?php endforeach ?>
</ul>
Close the previously created infrastructure
To cleanly finalize the page template we now close the previously opened WordPress loop and call the footer.
<?php endwhile; endif; ?><!-- end of the WP loop --> <?php get_footer(); ?>
The complete file may be found in this .zip file (275 KB).
Finally just use the new page template
To use the page template, just go to your admin panel, write a new page and choose your newly created page template – Voila: You have your first YAPB mosaic page!
Comment by Pierre Therrien
Comment by kd
Comment by Johannes
Comment by nasser q
what exactly do i do next? basically, i'm stuck on this part, where you say: "write a new page and choose your newly created page template"
can you maybe give more detailed steps as to how to do this?
thanks very much!
Comment by Johannes
Just go into your WP Admin Panel and write a new page. Before saving, go to the bottom of the edit page and open the tab "Page Template". You should see a list of all currently available templates including the new YAPB mosaic template.
Choose it, save, done ;-)
Comment by nasser q
Comment by nasser q
Comment by Graf
Comment by verdy
Comment by Johannes
Comment by jahmasta
I've try to use this sample code but i've only 5 images on my page ! Can i set up this ???
Thanks
Comment by jahmasta
Thanks
Comment by Johannes
Comment by jahmasta
Comment by Johannes
What means "dynamic"? Do you always post your images in other categories and if yes, how do you want to show them?
Beside of that, there's a forum for that:
http://johannes.jarolim.com/yapb-forum
Comment by Miss Britt
Comment by jahmasta
ID))): ?>
<a title="post_title ?>" href="ID) ?>"><img src="getThumbnailHref($thumbConfig) ?>" width="getThumbnailWidth($thumbConfig) ?>" height="getThumbnailHeight($thumbConfig) ?>" alt="post_title ?>" />
In this case we can see that we display 30 latest post of the category 18.
But in my case i want to catch the number of category in my loop with a little fonction but i don't know how can i do this.
For exemple i have 10 categorys. Now i'm obliged to make a template by category in order to display 30 thumbnails
of all pictures posts in each category.
I want to make a unique template witch call the id where i'm and diplay it in my wordpress loop.
Like this:
('category=18&numberposts=30');
i would have this ('category=[id where iam]&numberposts=30');
Thanks
Comment by sprouty
Comment by jack
Why in the mosaic page I get a vertical list of my photo and not mosaic style ?
helpppppp :(
Comment by Johannes
Comment by Owen
Thanks so much for YAPB. I also have the same problem, and was wondering what do you mean by the generated HTML elements? For more details see: http://twitter.com/findingnewo/status/1118111593
Thanks so much
Comment by Jamie Hansen
Comment by McAWilliams
// Let's get the last 1000 photoblog entries
$photography_posts = get_posts('category=' . get_option('yapb_default_post_category') . '&numberposts=50');
will obviously show up the last 50 images but I would love to paginate it if possible!
Comment by Johannes
http://weblogtoolscollection.com/archives/2008/04/19/paging-and-custom-wordpress-loops/
I'll try to make a little sample code page as soon as i've time.
Greets from Salzburg!
Comment by Kool
I am only getting 10 latest images with next/previous link below the thumbs. Thanks!
Comment by Bas
Comment by cody
"If you apply a “float:left” to each of the li tags in your unordered list, they should line up horizontally for you. Then, with some margin or padding, you can space them out as you need."
Comment by Phil
Comment by Temetus
How can I make pagination in to the mosaic page?
I think the php memory limit prevents me to show more than 294 posts ('&numberposts=294') at the time.. If I put 295 or more the page is just BLANK..
This USED to work, but now with WP 3.0.1 and the latest YAPB the mosaic page was just blank, so I had to limit the number of posts to 294 to show anything.
This is really annoying!
Comment by Peter
http://www.globinch.com/2010/11/01/how-to-create-wordpress-thumbnail-based-post-archives/
Comment by Eutur