$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Display first post of a term in taxonomy template|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Display first post of a term in taxonomy template

matteradmin12PV0评论

I have my template taxonomy-$taxonomy.php (here, 'catmaison').

In this taxonomy, I have 3 terms ('au-fil-du-temps', 'elaboration-distillation', 'plantes-epices').

Each terms of this taxonomy are displayed in my main menu.

I would like to display the first post of each term when i click in the menu.

Example : When I click on 'Au Fil Du Temps' in the menu, i would like to display the first post.

You can see my current code bellow :

<?php get_header(); ?>

<!-- CONTENT PAGE -->
<section class="sous-pages ptb-60" id="product-page" style="background: url('<?php echo $image['url']; ?>'); height: 700px;">
    <div class="container">

        <h1>taxonomy catmaison</h1>

        <div class="row">

            <?php

            $args = array(
                'post_type'             => 'maison',
                'posts_per_page'        => 1,
                'orderby'               => 'ASC',
                'ignore_sticky_posts'   => 1,
                'tax_query' => array(
                    'relation' => 'OR',
                    array(
                        'taxonomy' => 'catmaison',
                        'field'    => 'slug',
                        'terms'    => 'au-fil-du-temps',
                    ),
                    array(
                        'taxonomy' => 'catmaison',
                        'field'    => 'slug',
                        'terms'    => 'elaboration-distillation',
                    ),
                    array(
                        'taxonomy' => 'catmaison',
                        'field'    => 'slug',
                        'terms'    => 'plantes-epices',
                    ),
                ),
            );

            // Custom query.
            $query = new WP_Query( $args );

            // Check that we have query results.
            if ( $query->have_posts() ) {

            // Start looping over the query results.
            while ( $query->have_posts() ) {

            $query->the_post();

            ?>                

                <!-- PAGE CONTENT -->
                <div class="col-xl-4 offset-xl-6 product-type-2">
                    <h1>single produit</h1>
                    <h2><?php the_title(); ?></h2>
                    <hr>
                    <p class="intro-texte pb-20"><?php the_field('page_introduction'); ?></p>
                    <p><?php the_field('project_description'); ?></p>
                </div>

                <div class="col-xl-12">
                    <div class="float-left"><?php previous_post_link('%link','<img src="' . get_bloginfo("template_directory") . '/img/general/arrow_left_shadow.png" />'); ?></div>
                    <div class="float-right"><?php next_post_link('%link','<img src="' . get_bloginfo("template_directory") . '/img/general/arrow_right_shadow.png" />'); ?></div>
                </div>
                <!-- PAGE CONTENT -->

            <?php

            } // End while 
            } // End if

            else { echo '<p>Aucune actualité trouvée</p>'; } ?>

            <?php wp_reset_postdata(); ?> 

        </div><!-- End Row -->

    </div>
</section>
Post a comment

comment list (0)

  1. No comments so far