0

Is it's possible to have the startpage to also serve as an archive page?

The startpage has a lot of boxes for other different categories and taxonomies. For example this:

<div class="column box medium-box module">

    <header class="module-head"><h2>Art</h2></header>

    <ul class="posts-list">
    <?php
    $args = array(
        'posts_per_page' => 6, 
        'post__not_in'   => $do_not_duplicate,
        'category_name'  => 'art'
    );
    $myposts = get_posts($args);

    foreach ($myposts as $post) : setup_postdata($post);
    $do_not_duplicate[] = $post->ID;
    ?>
    <li>

        <?php get_template_part('template-parts/post/content', 'small'); ?>

    </li>
    <?php endforeach;
    wp_reset_postdata();?>
</ul>

</div>

Now, I want the taxonomy to be added to the arguments when the page serve as archive page.

1 Answer 1

0

Use the Taxonomy_Parameters in WordPress WP_Query like that:

$args = array(
    'posts_per_page' => 6, 
    'post__not_in'   => $do_not_duplicate,
    'tax_query' => array(
        'relation' => 'AND',
        array(
            'taxonomy' => 'category',
            'field'    => 'slug',
            'terms'    => 'art',
        ),
        array(
            'taxonomy' => 'country',
            'field'    => 'slug',
            'terms'    => 'france',
        ),
    ),
);
$myposts = get_posts($args);

you can add the "country" taxonomy to links as url parameters and get it when click the the like.

2
  • I'm not sure you understod me wrong. But I don't want country and category to be in the get query on startpage. Commented Aug 17, 2017 at 19:00
  • use is_tax() to identity the taxonomy page, if it returns true, we are on the taxonomy term archive page, include the category_name query arg.
    – Amos Lee
    Commented Aug 17, 2017 at 21:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.