I'm working on a WordPress theme and have created a file named all-posts.php
to display a list of all posts order by release date.
In my index.php
file, I have an anchor tag that I want to redirect the user to the all-posts.php
page and display its content.
What are the best approaches to achieve this?
You should create a page named "All Posts" in your Wordpress Backend, whose slug will be all-posts
.
Then you can create a php template file for that page, called page-all-posts.php and save it in your theme folder. There you will place all the php logic for retrieving and displaying posts.
Then, you can insert the url of that page inside the href of the anchor tag:
<?php
$page = get_page_by_path( 'all-posts' );
$permalink = get_permalink( $page->ID );
?>
<a href="<?php echo $permalink; ?>">All Posts</a>