• Hi, hopefully someone will be able to help me with this. I’m looking for something quite similar to this post… I’ll try to explain as simply as possible what I’ve got, and what I’m trying to achieve.

    This is for a gallery-style page for an artist, which (using the ‘Get Post Image’ plugin) pulls images from all blog posts and places them on this page along with the post title beneath. Each post in the blog is filed under a year category, for example I have 2010, 2009, 2008 etc. as categories. I’ve got this far, but I want to…

    • Display each image under a heading of its respective category (that I can apply a class to) e.g. 2010. The heading will feature once, with all images from posts under that category showing beneath.
    • Have each category heading also an anchor so I can link to that anchor in the sidebar and skip to that year on the page.

    This is the code for the gallery at the moment which takes the images from the posts an displays them on this page:

    query_posts(0 /*'category_name=uncategorized&showposts=6'*/);
    	while(have_posts())
    		{
    			the_post();
    			$image_tag = gpi_get_image(0);
    			$url = get_permalink();
    			echo "<a href='$url'><div class='galleryimage'>$image_tag<br /><div class='gallerytitle'>";
    			the_title();
    			echo "</div></div></a>";
    		}

    This works nicely, but now I want to split it up by category. I’ve tried to integrate the following code from the post linked above:

    $cat_args=array(
    	'orderby' => 'name',
    	'order' => 'DESC'
    	);
    $categories = get_categories($cat_args);
    foreach($categories as $category) {
    $args = array(
    	'showposts' => -1,
    	'category__in' => array($category->term_id),
    	'caller_get_posts'=>1
    	);
    $posts=get_posts($args);
    if ($posts) {
    echo '<a name="' . $category->name. '"></a><p class="topic-titles">' . $category->name . '</p> ';
    foreach($posts as $post) {
    setup_postdata($post);

    Though this is missing a couple of closing braces and I’m not sure how to join these two together to get what I need.

    If anyone could please help I’d be stoked. Thanks in advance!

  • The topic ‘Order images from posts by category on the same page’ is closed to new replies.