the_post example



get_header();

/* Start the Loop */
while ( have_posts() ) :
    the_post();
    get_template_part( 'template-parts/content/content-page' );

    // If comments are open or there is at least one comment, load up the comment template.     if ( comments_open() || get_comments_number() ) {
        comments_template();
    }
endwhile; // End of the loop.
get_footer();
(int) $wp_query->found_posts,
                    'twentytwentyone'
                )
            ),
            (int) $wp_query->found_posts
        );
        ?> </div><!-- .search-result-count --> <?php     // Start the Loop.     while ( have_posts() ) {
        the_post();

        /* * Include the Post-Format-specific template for the content. * If you want to override this in a child theme, then include a file * called content-___.php (where ___ is the Post Format name) and that will be used instead. */
        get_template_part( 'template-parts/content/content-excerpt', get_post_format() );
    } // End the loop.
    // Previous/next page navigation.     twenty_twenty_one_the_posts_navigation();

    

function the_post() {
    global $wp_query;

    if ( ! isset( $wp_query ) ) {
        return;
    }

    $wp_query->the_post();
}

/* * Comments loop. */

/** * Determines whether current WordPress query has comments to loop over. * * @since 2.2.0 * * @global WP_Query $wp_query WordPress Query object. * * @return bool True if comments are available, false if no more comments. */
<?php if ( have_posts() ) : ?> <header class="page-header alignwide"> <?php the_archive_title( '<h1 class="page-title">', '</h1>' ); ?> <?php if ( $description ) : ?> <div class="archive-description"><?php echo wp_kses_post( wpautop( $description ) ); ?></div> <?php endif; ?> </header><!-- .page-header --> <?php while ( have_posts() ) : ?> <?php the_post(); ?> <?php get_template_part( 'template-parts/content/content', get_theme_mod( 'display_excerpt_or_full_post', 'excerpt' ) ); ?> <?php endwhile; ?> <?php twenty_twenty_one_the_posts_navigation(); ?> <?php else : ?> <?php get_template_part( 'template-parts/content/content-none' ); ?> <?php endif; ?> <?php get_footer();
<?php     /** * Fires at the end of the RSS Feed Header. * * @since 2.0.0 */
    do_action( 'rss_head' );
    ?> <?php while ( have_posts() ) :
    the_post();
    ?> <item> <title><?php the_title_rss(); ?></title> <description><![CDATA[<?php the_excerpt_rss(); ?>]]></description> <link><?php the_permalink_rss(); ?></link> <?php         /** * Fires at the end of each RSS feed item. * * @since 2.0.0 */
        
    /** * Fires at the end of the RDF feed header. * * @since 2.0.0 */
    do_action( 'rdf_header' );
    ?> <items> <rdf:Seq> <?php         while ( have_posts() ) :
            the_post();
            ?> <rdf:li rdf:resource="<?php the_permalink_rss(); ?>"/> <?php endwhile; ?> </rdf:Seq> </items> </channel> <?php rewind_posts();
while ( have_posts() ) :
    the_post();
    ?>

function render_block_core_post_featured_image( $attributes$content$block ) {
    if ( ! isset( $block->context['postId'] ) ) {
        return '';
    }
    $post_ID = $block->context['postId'];

    // Check is needed for backward compatibility with third-party plugins     // that might rely on the `in_the_loop` check; calling `the_post` sets it to true.     if ( ! in_the_loop() && have_posts() ) {
        the_post();
    }

    $is_link        = isset( $attributes['isLink'] ) && $attributes['isLink'];
    $size_slug      = isset( $attributes['sizeSlug'] ) ? $attributes['sizeSlug'] : 'post-thumbnail';
    $attr           = get_block_core_post_featured_image_border_attributes( $attributes );
    $overlay_markup = get_block_core_post_featured_image_overlay_element_markup( $attributes );

    if ( $is_link ) {
        if ( get_the_title( $post_ID ) ) {
            $attr['alt'] = trim( strip_tags( get_the_title( $post_ID ) ) );
        } else {
            
public function display_rows() {
        global $post$wp_query;

        $post_ids = wp_list_pluck( $wp_query->posts, 'ID' );
        reset( $wp_query->posts );

        $this->comment_pending_count = get_pending_comments_num( $post_ids );

        add_filter( 'the_title', 'esc_html' );

        while ( have_posts() ) :
            the_post();

            if ( $this->is_trash && 'trash' !== $post->post_status
                || ! $this->is_trash && 'trash' === $post->post_status
            ) {
                continue;
            }

            $post_owner = ( get_current_user_id() === (int) $post->post_author ) ? 'self' : 'other';
            ?> <tr id="post-<?php echo $post->ID; ?>" class="<?php echo trim( ' author-' . $post_owner . ' status-' . $post->post_status ); ?>"> <?php $this->single_row_columns( $post ); ?>
<?php if ( is_home() && ! is_front_page() && ! empty( single_post_title( '', false ) ) ) : ?> <header class="page-header alignwide"> <h1 class="page-title"><?php single_post_title(); ?></h1> </header><!-- .page-header --> <?php endif; ?> <?php if ( have_posts() ) {

    // Load posts loop.     while ( have_posts() ) {
        the_post();

        get_template_part( 'template-parts/content/content', get_theme_mod( 'display_excerpt_or_full_post', 'excerpt' ) );
    }

    // Previous/next page navigation.     twenty_twenty_one_the_posts_navigation();

} else {

    // If no content, include the "No posts found" template.     get_template_part( 'template-parts/content/content-none' );

}
return $is_debug ?
            // translators: Visible only in the front end, this warning takes the place of a faulty block.             __( '[block rendering halted]' ) :
            '';
    }

    $seen_ids[ $post_id ] = true;

    // Check is needed for backward compatibility with third-party plugins     // that might rely on the `in_the_loop` check; calling `the_post` sets it to true.     if ( ! in_the_loop() && have_posts() ) {
        the_post();
    }

    // When inside the main loop, we want to use queried object     // so that `the_preview` for the current post can apply.     // We force this behavior by omitting the third argument (post ID) from the `get_the_content`.     $content = get_the_content();
    // Check for nextpage to display page links for paginated posts.     if ( has_block( 'core/nextpage' ) ) {
        $content .= wp_link_pages( array( 'echo' => 0 ) );
    }

    
<?php self_link(); ?>" /> <?php     /** * Fires just before the first Atom feed entry. * * @since 2.0.0 */
    do_action( 'atom_head' );

    while ( have_posts() ) :
        the_post();
        ?> <entry> <author> <name><?php the_author(); ?></name> <?php             $author_url = get_the_author_meta( 'url' );
            if ( ! empty( $author_url ) ) :
                ?> <uri><?php the_author_meta( 'url' ); ?></uri> <?php             endif;

            


get_header( 'embed' );

if ( have_posts() ) :
    while ( have_posts() ) :
        the_post();
        get_template_part( 'embed', 'content' );
    endwhile;
else :
    get_template_part( 'embed', '404' );
endif;

get_footer( 'embed' );


get_header();

// Start the loop. while ( have_posts() ) {
    the_post();
    ?> <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <header class="entry-header alignwide"> <?php the_title( '<h1 class="entry-title">', '</h1>' ); ?> </header><!-- .entry-header --> <div class="entry-content"> <figure class="wp-block-image"> <?php                 /** * Filter the default image attachment size. * * @since Twenty Twenty-One 1.0 * * @param string $image_size Image size. Default 'full'. */


get_header();

/* Start the Loop */
while ( have_posts() ) :
    the_post();

    get_template_part( 'template-parts/content/content-single' );

    if ( is_attachment() ) {
        // Parent post navigation.         the_post_navigation(
            array(
                /* translators: %s: Parent post link. */
                'prev_text' => sprintf( __( '<span class="meta-nav">Published in</span><span class="post-title">%s</span>', 'twentytwentyone' ), '%title' ),
            )
        );
    }
echo '<div id="' . $args['id'] . '" class="activity-block">';

        echo '<h3>' . $args['title'] . '</h3>';

        echo '<ul>';

        $today    = current_time( 'Y-m-d' );
        $tomorrow = current_datetime()->modify( '+1 day' )->format( 'Y-m-d' );
        $year     = current_time( 'Y' );

        while ( $posts->have_posts() ) {
            $posts->the_post();

            $time = get_the_time( 'U' );

            if ( gmdate( 'Y-m-d', $time ) === $today ) {
                $relative = __( 'Today' );
            } elseif ( gmdate( 'Y-m-d', $time ) === $tomorrow ) {
                $relative = __( 'Tomorrow' );
            } elseif ( gmdate( 'Y', $time ) !== $year ) {
                /* translators: Date and time format for recent posts on the dashboard, from a different calendar year, see https://www.php.net/manual/datetime.format.php */
                $relative = date_i18n( __( 'M jS Y' )$time );
            } else {
                
Home | Imprint | This part of the site doesn't use cookies.