$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'); ?>How to add navigation arrows to manually slide through posts?|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)

How to add navigation arrows to manually slide through posts?

matteradmin7PV0评论

I have made this:

    <?php 

    $args = array( 'numberposts' => '5' );
    $recent_posts = wp_get_recent_posts($args);
    foreach( $recent_posts as $recent ){
        if($recent['post_status']=="publish"){
            echo '<li class="one_sixth">
            <a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >' .   get_the_post_thumbnail($recent["ID"], 'thumbnail').'<div class="browse_category_name"> ' . $recent["post_title"]. '<div class="author"> <span>Author: </span> ' . get_the_author_meta('display_name', $recent["post_author"]). '</div></div></a></li> ';
        } else{
            echo '<li class="one_third">
            <a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >' .   $recent["post_title"].'</a></li> ';
        }
         }
    ?>

So, what I want to achieve is... to make "navigation" arrows that will navigate one by one through these posts when you click on the arrow (think like a carrousel), yet I have no idea how I can do this.

Where to start and what to do? Could someone help me out with it, please?

I have made this:

    <?php 

    $args = array( 'numberposts' => '5' );
    $recent_posts = wp_get_recent_posts($args);
    foreach( $recent_posts as $recent ){
        if($recent['post_status']=="publish"){
            echo '<li class="one_sixth">
            <a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >' .   get_the_post_thumbnail($recent["ID"], 'thumbnail').'<div class="browse_category_name"> ' . $recent["post_title"]. '<div class="author"> <span>Author: </span> ' . get_the_author_meta('display_name', $recent["post_author"]). '</div></div></a></li> ';
        } else{
            echo '<li class="one_third">
            <a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >' .   $recent["post_title"].'</a></li> ';
        }
         }
    ?>

So, what I want to achieve is... to make "navigation" arrows that will navigate one by one through these posts when you click on the arrow (think like a carrousel), yet I have no idea how I can do this.

Where to start and what to do? Could someone help me out with it, please?

Share Improve this question asked May 3, 2017 at 17:49 SiyahSiyah 1932 silver badges12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Your code suggests that you want a list of 5 most recent posts. There is no navigation for a list, unless you use paging. It is different, when you display a single post page. Then you can navigate to 'next' or 'previous' post, with help of the_post_navigation() template function. See it in Code Reference.

I've modified slightly your code, by adding 'post_status' => 'publish' to $args array, so you don't need to check the status. Cleaned up incorrect nesting of HTML tags, as well. New code:

<?php 
    $args = array( 'numberposts' => '5', 'post_status' => 'publish' );
    $recent_posts = wp_get_recent_posts($args);
    echo '<ul>';
    foreach( $recent_posts as $recent ) {
        echo '<li class="one_sixth" style="list-style-position: outside;"><a href="' . get_permalink( $recent["ID"] ) . '" title="See ' . esc_attr( $recent["post_title"] ) . '" >' . $recent["post_title"] . '</a><br>Author: ' . get_the_author_meta( 'display_name', $recent["post_author"] ) . '</li> ';
    }
    wp_reset_query();
    echo '</ul>';
Post a comment

comment list (0)

  1. No comments so far