have_posts example



get_header(); ?> <?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();

}
/** * The template for displaying image attachments * * @package WordPress * @subpackage Twenty_Twenty_One * @since Twenty Twenty-One 1.0 */

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'. */
if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) {
            return 'delete_all';
        }

        return parent::current_action();
    }

    /** * @return bool */
    public function has_items() {
        return have_posts();
    }

    /** */
    public function no_items() {
        if ( $this->is_trash ) {
            _e( 'No media files found in Trash.' );
        } else {
            _e( 'No media files found.' );
        }
    }

    


get_header();

if ( have_posts() ) {
    ?> <header class="page-header alignwide"> <h1 class="page-title"> <?php             printf(
                /* translators: %s: Search term. */
                esc_html__( 'Results for "%s"', 'twentytwentyone' ),
                '<span class="page-description search-term">' . esc_html( get_search_query() ) . '</span>'
            );
            ?> </h1> </header><!-- .page-header --> <div class="search-result-count default-max-width">
'posts_per_page'         => 10,
                    'post_type'              => $matches[2],
                    's'                      => $query,
                )
            );

            if ( isset( $post_type_obj->_default_query ) ) {
                $args = array_merge( $args(array) $post_type_obj->_default_query );
            }

            $search_results_query = new WP_Query( $args );
            if ( ! $search_results_query->have_posts() ) {
                return;
            }

            while ( $search_results_query->have_posts() ) {
                $post = $search_results_query->next_post();

                if ( 'markup' === $response_format ) {
                    $var_by_ref = $post->ID;
                    echo walk_nav_menu_tree(
                        array_map( 'wp_setup_nav_menu_item', array( get_post( $var_by_ref ) ) ),
                        0,
                        
<?php bloginfo_rss( 'language' ); ?></language> <?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 */


get_header();

$description = get_the_archive_description();
?> <?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' ) ); ?>


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();
echo apply_filters( 'rss_update_frequency', $frequency );
    ?> </sy:updateFrequency> <?php     /** * Fires at the end of the RSS2 Feed Header. * * @since 2.0.0 */
    do_action( 'rss2_head' );

    while ( have_posts() ) :
        the_post();
        ?> <item> <title><?php the_title_rss(); ?></title> <link><?php the_permalink_rss(); ?></link> <?php if ( get_comments_number() || comments_open() ) : ?> <comments><?php comments_link_feed(); ?></comments> <?php endif; ?> <dc:creator><![CDATA[<?php the_author(); ?>]]></dc:creator> <pubDate><?php echo mysql2date( 'D, d M Y H:i:s +0000', get_post_time( 'Y-m-d H:i:s', true ), false ); ?></pubDate>
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 ) );
    }

    

function get_feed_build_date( $format ) {
    global $wp_query;

    $datetime          = false;
    $max_modified_time = false;
    $utc               = new DateTimeZone( 'UTC' );

    if ( ! empty( $wp_query ) && $wp_query->have_posts() ) {
        // Extract the post modified times from the posts.         $modified_times = wp_list_pluck( $wp_query->posts, 'post_modified_gmt' );

        // If this is a comment feed, check those objects too.         if ( $wp_query->is_comment_feed() && $wp_query->comment_count ) {
            // Extract the comment modified times from the comments.             $comment_times = wp_list_pluck( $wp_query->comments, 'comment_date_gmt' );

            // Add the comment times to the post times for comparison.             $modified_times = array_merge( $modified_times$comment_times );
        }

        


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' );
// Override the custom query with the global query if needed.     $use_global_query = ( isset( $block->context['query']['inherit'] ) && $block->context['query']['inherit'] );
    if ( $use_global_query ) {
        global $wp_query;
        $query = $wp_query;
    } else {
        $query_args = build_query_vars_from_query_block( $block$page );
        $query      = new WP_Query( $query_args );
    }

    if ( $query->have_posts() ) {
        return '';
    }

    if ( ! $use_global_query ) {
        wp_reset_postdata();
    }

    $classes            = ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) ? 'has-link-color' : '';
    $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );
    return sprintf(
        '<div %1$s>%2$s</div>',
        
array(
                        'taxonomy' => 'wp_theme',
                        'field'    => 'name',
                        'terms'    => $attributes['theme'],
                    ),
                ),
                'posts_per_page'      => 1,
                'no_found_rows'       => true,
                'lazy_load_term_meta' => false, // Do not lazy load term meta, as template parts only have one term.             )
        );
        $template_part_post  = $template_part_query->have_posts() ? $template_part_query->next_post() : null;
        if ( $template_part_post ) {
            // A published post might already exist if this template part was customized elsewhere             // or if it's part of a customized template.             $content    = $template_part_post->post_content;
            $area_terms = get_the_terms( $template_part_post, 'wp_template_part_area' );
            if ( ! is_wp_error( $area_terms ) && false !== $area_terms ) {
                $area = $area_terms[0]->name;
            }
            /** * Fires when a block template part is loaded from a template post stored in the database. * * @since 5.9.0 * * @param string $template_part_id The requested template part namespaced to the theme. * @param array $attributes The block attributes. * @param WP_Post $template_part_post The template part post object. * @param string $content The template part content. */
array(
                'total_items' => $total_items,
                'per_page'    => $per_page,
            )
        );
    }

    /** * @return bool */
    public function has_items() {
        return have_posts();
    }

    /** */
    public function no_items() {
        if ( isset( $_REQUEST['post_status'] ) && 'trash' === $_REQUEST['post_status'] ) {
            echo get_post_type_object( $this->screen->post_type )->labels->not_found_in_trash;
        } else {
            echo get_post_type_object( $this->screen->post_type )->labels->not_found;
        }
    }

    
Home | Imprint | This part of the site doesn't use cookies.