最新消息: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)

Default archive URL wordpress

matteradmin8PV0评论

In wordpress you have a few 'default' archive URL's. Like for example: / generates an overview of the posts of (only) that year.

If you have an category blogs the url / generates an overview of all the posts within that category. (Spread over multiple pages)

Now is my question is there any link which generates an overview of all posts (spread over multiple pages) starting with the newest first and going back in time?

So not like the 2011 url, which only fetches from this year, but go's further back in time when applicable.

My current permalink structure is:

/%category%/%postname%/

Thanks.

In wordpress you have a few 'default' archive URL's. Like for example: http://www.mydomain/2011/ generates an overview of the posts of (only) that year.

If you have an category blogs the url http://www.mydomain/blogs/ generates an overview of all the posts within that category. (Spread over multiple pages)

Now is my question is there any link which generates an overview of all posts (spread over multiple pages) starting with the newest first and going back in time?

So not like the 2011 url, which only fetches from this year, but go's further back in time when applicable.

My current permalink structure is:

/%category%/%postname%/

Thanks.

Share Improve this question asked Oct 2, 2011 at 10:02 MatthijnMatthijn
Add a comment  | 

4 Answers 4

Reset to default 19

This may be an old question, but all the answers here are incorrect.

If the front page is set to a static page, and another page is set to the blog page, this will dynamically fetch and echo the URL for the blog archive page (i.e. blog index page)...

<?php echo get_permalink( get_option( 'page_for_posts' ) ) ?>

This first fetches the page id for your blog page (from your site options), then fetches the permalink for that page id.

From a coding standpoint, WordPress assumes that your homepage and your blog page are one and the same. This is vestigial functionality from the days when WordPress was literally just a blog system, and not the full-featured CMS it has become. As such, you cannot generally trust the naming convention of WordPress's core functions.

FOR EXAMPLE: home_url() will generally return your homepage, whatever it is... which may not necessarily be your main blog archive/index. However, the conditional is_home() function returns true only for your main blog archive not your actual homepage (which is tested using is_front_page()).

You're basically asking for the Blog Posts Index, which queries all blog posts, ever.

If your site is configured to display the Blog Posts Index on the front page, then the URL you're after is simply home_url().

If your site is configured to display a static Page on the front page, and to display blog Posts on static Page "Foobar", then the URL you're after is home_url( '/foobar' ) (or, more generically: home_url( '/' . get_option( 'page_for_posts' ) )).

The Blog Posts Index is a paginated archive index, so to get to the pages for older posts, simply append /page/#/, e.g. example/page/2/ or example/blog/page/2/.

http://myblog/?post_type=post for a list of all posts, probably sorted in descending order by date.

Specifying post_type in the query vars signals to WP_Query that you're looking for an archive page, so it will go through your template hierarchy looking first for archive-{post_type}.php and if that doesn't exists, archive.php in order to display the posts.

Do note that the number of posts displayed will still be guided by posts_per_page, which if not explicitly set, would use the setting in your Admin control panel under Settings > Reading > 'Blog pages show at most' # posts

If you want an archive for a custom post type that you created using the Custom Post Type UI plugin (CPT UI), you need to first enable an archive for that post type in the CPT UI settings when you add/edit that post type by setting the option to True.

The CPT UI options are found at:

example/wp-admin/admin.php?page=cptui_manage_post_types&action=edit

By default, the archive URL for the custom post type will be the slug you chose for the custom post type. You can also enter a custom slug to be used for the archive.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far