• Resolved Turtles

    (@turtles)


    Hi

    I am running a travel blog and I try to display a specific list of articles on the frontpage.

    I traveled from 2011 until now in many countries. Every post has a date of course and a category (the country). For every year (2014, 2013, 2012, 2011), I want to display 1 post (the last one) for every country visited.

    It should look like this :

    2014
    – Australia : last article about Australia written in 2014

    2013
    – Australia : last article about Australia written in 2013
    – Papoua new guinea : last article about PNG written in 2013
    – Indonesia : last article about Indonesia written in 2013
    – Malaysia : last article about Malaysia written in 2013
    etc

    The list template, if it can help : https://img4.hostingpics.net/pics/128237listarticles.jpg

    Do you think it is achievable with a custom query, SQL, hook… ? Or will it need some post processing in php or js for example ?

    I haven’t tried yet because I know I will need help to achieve it. I will begin now and report my progress here.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Turtles

    (@turtles)

    Still digging into queries.

    I will give a try with multiple queries, 1 per year as it will dramatically simplify the query and make it simple to put my divs containing years.

    <div>2014</div>
    -article
    -article
    -article
    <div>2013</div>
    -article
    etc

    Thread Starter Turtles

    (@turtles)

    It’s working with 1 loop per year. It suits me.
    I found the code somewhere else and just add the date condition.
    For example for year 2011 :

    <?php
    				//for each category, show one post
    				$cat_args=array(
    				  'orderby' => 'name',
    				  'order' => 'ASC'
    				   );
    				$categories=get_categories($cat_args);
    				  foreach($categories as $category) {
    				    $args=array(
    					'showposts' => 1,
    					'category__in' => array($category->term_id),
    					'caller_get_posts'=>1,
    					'year'=>2011
    				    );
    				    $posts=get_posts($args);
    					if ($posts) {
    					  echo '<p><a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';
    					  foreach($posts as $post) {
    					    setup_postdata($post); ?>
    					    <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
    					    <?php
    					  } // foreach($posts
    					} // if ($posts
    				    } // foreach($categories
    				?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Complex query. Don't know where to start’ is closed to new replies.