admin管理员组

文章数量:1252691

I can't believe I did not find the right function for this: I just want to retrieve the blog index url from a template.

My homepage is a static page. I am not looking for bloginfo('url') because it gives me my root url (/). I am looking for mysite/Blog

I am thinking about getting it via get_permalink($mypageid) but it is a bit dirty.

I can't believe I did not find the right function for this: I just want to retrieve the blog index url from a template.

My homepage is a static page. I am not looking for bloginfo('url') because it gives me my root url (/). I am looking for mysite/Blog

I am thinking about getting it via get_permalink($mypageid) but it is a bit dirty.

Share Improve this question asked Jun 6, 2013 at 8:44 Paul EtienneyPaul Etienney 1154 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 4

if you are referring to the 'posts page' as set under dashboard - settings - reading:

<?php 
if( get_option( 'page_for_posts' ) ) { 
  echo get_permalink( get_option( 'page_for_posts' ) ); 
} else { 
  echo home_url(); 
} 
?>

<?php echo home_url(); ?> <-- Set in Settings > General > WordPress address

<?php echo site_url(); ?> <-- Set in Settings > General > Site address

To get the Blog URL you can use the below code.

get_permalink( get_option( 'page_for_posts' ) );

If you are using WordPress 4.5+ then you can use the below code which will work for any post type.

get_post_type_archive_link( 'post' );

本文标签: permalinksLink to blog index from template