WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] template tag to get URL for blog page when using static homepage? (4 posts)

  1. tirussell
    Member
    Posted 3 years ago #

    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?

  2. esmi
    Theme Diva & Forum Moderator
    Posted 3 years ago #

    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

  3. tirussell
    Member
    Posted 3 years ago #

    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?

  4. esmi
    Theme Diva & Forum Moderator
    Posted 3 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic