在 WordPress 中获取博客页面 url

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40099994/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 11:15:30  来源:igfitidea点击:

get blog page url in WordPress

wordpress

提问by AceKD

The blog page on my WordPress website is set to be a different page other than the home page. I want to get the link to this blog page from any other pages.

我的 WordPress 网站上的博客页面设置为与主页不同的页面。我想从任何其他页面获取到此博客页面的链接。

How can I get blog page url?

如何获取博客页面网址?

回答by Samir Sheikh

You can use get_optionof page_for_poststo get the page ID to either assign it to a variable or to echo it.

您可以使用get_optionofpage_for_posts来获取页面 ID 以将其分配给变量或回显它。

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

For more information of the default get_optionvisit: Option Reference

更多默认信息get_option请访问:Option Reference

回答by admcfajn

We can use get_post_type_archive_linksince WordPress 4.5

WordPress 4.5 开始,我们可以使用get_post_type_archive_link

get_post_type_archive_link( 'post' );

回答by david Hymanson

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

回答by Manthan Dave

$posts_page_url is the url to blog page and $posts_page_title is the page title

$posts_page_url 是博客页面的 url,$posts_page_title 是页面标题

<?php
$posts_page_id = get_option( 'page_for_posts');
$posts_page = get_page( $posts_page_id);
$posts_page_title = $posts_page->post_title;
$posts_page_url = get_page_uri($posts_page_id  );
?>

More details refer the link - http://www.queness.com/code-snippet/7935/how-to-get-url-for-blog-page-when-using-static-homepage

更多细节参考链接 - http://www.queness.com/code-snippet/7935/how-to-get-url-for-blog-page-when-using-static-homepage

回答by elnaz

use this code:

使用此代码:

<?php echo '<a href="' . get_permalink( get_option( 'page_for_posts' ) ) . '">Our Blog</a>'; ?>

回答by Pytagoralf

Just call your url with this extention and all blog posts are displayed.

只需使用此扩展名调用您的 url,就会显示所有博客文章。

https://www.yourdomain.com/?post_type=post

https://www.yourdomain.com/?post_type=post