Support » Themes and Templates » template tag to get URL for blog page when using static homepage?

  • Resolved tirussell

    (@tirussell)


    Once a site has been set up to use a static front page, is there something like get_bloginfo(‘url’) that will give me the URL and title of the page that has been designated as the blog/news/etc page?

Viewing 3 replies - 1 through 3 (of 3 total)
  • get_option( 'page_for_posts') will give you the id of the designated posts page if get_option( 'show_on_front' ) is set to page. so something like:

    if( get_option('show_on_front') == 'page') {
    	$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  );
    }
    else $posts_page_title = $posts_page_url = '';

    should work.

    http://codex.wordpress.org/Option_Reference
    http://codex.wordpress.org/Function_Reference/get_page
    http://codex.wordpress.org/Function_Reference/get_page_uri

    Thread Starter tirussell

    (@tirussell)

    Thanks for cluing me into ‘page_for_posts’ – your solution works like a charm. I added the following to my functions.php:

    if ( ! function_exists( 'mytheme_get_posts_page' ) ) :
    
    function mytheme_get_posts_page($info) {
    	if( get_option('show_on_front') == 'page') {
    		$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  );
    	}
    	else $posts_page_title = $posts_page_url = '';
    
    	if ($info == 'url') {
    		return $posts_page_url;
    	} elseif ($info == 'title') {
    		return $posts_page_title;
    	} else {
    		return false;
    	}
    }
    endif;

    seems like this is something that people who are using a static homepage/wordpress as a cms would like access to. What’s the best way to suggest something similar to this for consideration as an out-of-the-box function in future releases?

    You could try posting something in the Requests & Feedback forum.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘template tag to get URL for blog page when using static homepage?’ is closed to new replies.