$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'); ?>php - WordPress Recent Posts - Loop|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)

php - WordPress Recent Posts - Loop

matteradmin9PV0评论

I would greatly appreciate some help, I have written a loop inside a list item however I'm looking to set a width and height on the thumbnail and display some expert "text" but limit the length of it...

<ul>
    <!-- Define our WP Query Parameters -->
    <?php $the_query = new WP_Query( 'posts_per_page=3' ); ?>

    <!-- Start our WP Query -->
    <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>

    <li>
        <?php 

            if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
               the_post_thumbnail('large');
            }
        ?>

        <a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
    </li>

    <!-- Repeat the process and reset once it hits the limit -->
    <?php

    endwhile;
    wp_reset_postdata();
    ?>
</ul>

I would greatly appreciate some help, I have written a loop inside a list item however I'm looking to set a width and height on the thumbnail and display some expert "text" but limit the length of it...

<ul>
    <!-- Define our WP Query Parameters -->
    <?php $the_query = new WP_Query( 'posts_per_page=3' ); ?>

    <!-- Start our WP Query -->
    <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>

    <li>
        <?php 

            if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
               the_post_thumbnail('large');
            }
        ?>

        <a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
    </li>

    <!-- Repeat the process and reset once it hits the limit -->
    <?php

    endwhile;
    wp_reset_postdata();
    ?>
</ul>
Share Improve this question asked Dec 23, 2018 at 19:26 Joshua CurtisJoshua Curtis 11 bronze badge 1
  • Added a function expert length which has worked! however not sure about the thumbnail I know you can set sizes "large" etc however can I define the height and width? – Joshua Curtis Commented Dec 23, 2018 at 19:37
Add a comment  | 

1 Answer 1

Reset to default 0

Add this function in your functions.php for specific size of thumbnail

add_image_size( 'custom-size', 220, 180 );

and fetch custom-size image. For excerpt length use this function.

function wp_example_excerpt_length( $length ) {
   return 30; 
} 
add_filter( 'excerpt_length', 'wp_example_excerpt_length');

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far