[wp-trac] [WordPress Trac] #27054: Provide a Standard Post Format archive view
WordPress Trac
noreply at wordpress.org
Sun Feb 25 16:49:06 UTC 2024
#27054: Provide a Standard Post Format archive view
--------------------------+------------------------
Reporter: sixhours | Owner: (none)
Type: enhancement | Status: closed
Priority: normal | Milestone:
Component: Post Formats | Version:
Severity: normal | Resolution: duplicate
Keywords: | Focuses:
--------------------------+------------------------
Comment (by mizuki1rg):
To create an archive view specifically for posts with the Standard format,
you can customize your theme's template files. Below is a basic example of
how you might accomplish this:
Create a Custom Archive Template:
In your theme directory, duplicate your theme's archive.php file and name
it something like archive-standard.php.
Modify the Template:
Edit archive-standard.php to include a custom query to retrieve only posts
with the Standard format. You can achieve this by utilizing the tax_query
parameter with the post_format taxonomy.
{{{#!php
<?php
php
<?php
/*
* Template Name: Standard Post Archive
* Description: A custom archive template for posts with the Standard
format.
*/
get_header();
?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<header class="page-header">
<h1 class="page-title"><?php _e( 'Standard Post Archive',
'your-theme-textdomain' ); ?></h1>
</header>
<?php
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => 'post-format-standard', // Standard
format slug
),
),
);
$standard_posts = new WP_Query( $args );
if ( $standard_posts->have_posts() ) :
while ( $standard_posts->have_posts() ) :
$standard_posts->the_post();
// Output your post content here
endwhile;
else :
// No posts found
get_template_part( 'template-parts/content', 'none' );
endif;
wp_reset_postdata();
?>
</main><!-- #main -->
</div><!-- #primary -->
<?php
}}}
get_footer();
Customize Output:
Within the loop, customize how each post is displayed according to your
theme's design. You might use get_template_part() to include the standard
post format template parts.
Create a Page:
After saving your archive-standard.php file, create a new page in
WordPress and assign the "Standard Post Archive" template to it. This page
will now display your archive of posts with the Standard format.
Optional: Styling:
You may need to add custom CSS to style the archive page according to your
theme's design.
By following these steps, you can create a custom archive view
specifically for posts with the Standard format in your WordPress theme
--
Ticket URL: <https://core.trac.wordpress.org/ticket/27054#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list