Make WordPress Core

Opened 12 years ago

Closed 8 years ago

#19902 closed feature request (fixed)

blog_url() and get_blog_url() template tags

Reported by: johnjamesjacoby's profile johnjamesjacoby Owned by: ericlewis's profile ericlewis
Milestone: 4.5 Priority: normal
Severity: normal Version: 3.3.1
Component: Permalinks Keywords:
Focuses: Cc:

Description (last modified by johnjamesjacoby)

With usage of WordPress as a CMS increasing, the blog is not always the focal point. It would be great if there were template tags available to get the blog url, basically a wrapper for getting the options if it's set to a WordPress page, and defaulting to home_url( '/' ) if not.

Patched against r19759 (trunk)

Attachments (4)

19902.diff (1.5 KB) - added by johnjamesjacoby 12 years ago.
19902.2.diff (2.5 KB) - added by ericlewis 8 years ago.
19902.3.diff (2.5 KB) - added by ericlewis 8 years ago.
19902.4.diff (1.9 KB) - added by ericlewis 8 years ago.

Download all attachments as: .zip

Change History (35)

#1 follow-ups: @nacin
12 years ago

Since we already have site_url(), let's try to pick a name that is less confusing. Perhaps blog_page_url() or something.

This might be a duplicate of another ticket, but I'm not locating anything.

#2 in reply to: ↑ 1 ; follow-up: @johnjamesjacoby
12 years ago

Replying to nacin:

Since we already have site_url(), let's try to pick a name that is less confusing. Perhaps blog_page_url() or something.

This might be a duplicate of another ticket, but I'm not locating anything.

Agree the nomenclature gets increasingly confusing. Possible permutations:

  • get_/blog_url()
  • get_/blog_link()
  • get_/blog_permalink()
  • get_/blog_page_url()
  • get_/blog_page_link()
  • get_/blog_page_permalink()
Version 0, edited 12 years ago by johnjamesjacoby (next)

#3 @johnjamesjacoby
12 years ago

  • Description modified (diff)

#4 @evansolomon
12 years ago

I wrote a similar patch before finding this ticket, which covers pretty much everything I thought of. An additional idea I had was to return the last post if the blog uses a static front page but doesn't have a posts page set. In that case, I think the last post (if one exists) makes the most sense as their blog URL.

#5 in reply to: ↑ 1 @ericlewis
11 years ago

This is sorely needed.

Replying to nacin:

Since we already have site_url(), let's try to pick a name that is less confusing. Perhaps blog_page_url() or something.

I'm good with get_blog_url(), it fits well with the other link template tags we already have.

#6 @SergeyBiryukov
10 years ago

#25423 was marked as a duplicate.

#7 @SergeyBiryukov
10 years ago

Found a use case for get_blog_url() in wp_list_categories():
tags/3.6.1/wp-includes/category-template.php#L460.

#8 in reply to: ↑ 2 @ericlewis
10 years ago

Replying to johnjamesjacoby:

Agree the nomenclature gets increasingly confusing.

get_blog_index_url() and blog_index_url() is another naming option that read less confusing to me than get_blog_page_url() and blog_page_url(), and more specific than blog_url() and get_blog_url()

#9 @nacin
10 years ago

  • Component changed from Template to Permalinks

#10 @johnjamesjacoby
10 years ago

I can get with get_blog_index_url() and blog_index_url(), and I still believe these helper functions would be highly useful to plugin developers and on multisite/network installs.

#11 follow-up: @SergeyBiryukov
10 years ago

It would be great if there were template tags available to get the blog url, basically a wrapper for getting the options if it's set to a WordPress page, and defaulting to home_url( '/' ) if not.

This sounds similar to how is_front_page() works, so I'd suggest get_front_page_url() and front_page_url() for consistency.

#12 in reply to: ↑ 11 @johnjamesjacoby
10 years ago

Replying to SergeyBiryukov:

This sounds similar to how is_front_page() works, so I'd suggest get_front_page_url() and front_page_url() for consistency.

is_front_page() and is_home() are only two poorly-named parts of the equation.

  • Getting the front-page URL is easy; it's always the root of the site domain + path. This can be done quite easily virtually anywhere (wp_options, wp_blogs, wp_site, wp_bp_blogs for buddypress.) We have helper functions to tell us whether or not there are posts at this root location, but no function to return the URL if they are not.
  • Getting the blog-index URL is less-easy, requiring something akin to the attached patch. Once the post index is changed from the root/front/home, it could reside almost anywhere. The attached patch attempts to shed light on where that might be, from outside the context of the current blog/site/network.

#13 @chriscct7
8 years ago

  • Keywords needs-patch needs-unit-tests added; has-patch 2nd-opinion removed
  • Milestone changed from Awaiting Review to Future Release
  • Owner set to chriscct7
  • Status changed from new to assigned

#14 @ericlewis
8 years ago

  • Milestone changed from Future Release to 4.5

@ericlewis
8 years ago

#15 @ericlewis
8 years ago

  • Keywords has-patch has-unit-tests added; needs-patch needs-unit-tests removed

In attachment:19902.2.diff,

  • Removing the_blog_url() for the moment, which echoes the URL. Do we want this? get_site_url() and get_home_url() don't have echoing equivalents.
  • Added two unit tests.
  • Fixed up docs.

#16 @ericlewis
8 years ago

  • Keywords dev-feedback added

Let's circle back to function naming. These options are on the table:

  1. Since we have get_post_type_archive_link() for custom post types, perhaps get_post_archive_link()?
  2. get_blog_index_url()
  3. get_blog_page_url()

I lean towards the first. It's to the point, echoes other existing functions, and doesn't introduce new jargon ("blog index") or awkward naming ("blog page").

#17 follow-ups: @swissspidy
8 years ago

I tend to think get_post_type_archive_link() should just work for posts too, being in line with other post types and therefore making #35306 a duplicate of this ticket.

At least get_blog_url() (or whatever it is called) should just be a wrapper for that.

Minor nitpicking: $this->assertSame( $actual, $expected ); should be $this->assertSame( $expected, $actual );

#18 in reply to: ↑ 17 @ericlewis
8 years ago

Replying to swissspidy:

I tend to think get_post_type_archive_link() should just work for posts too, being in line with other post types and therefore making #35306 a duplicate of this ticket.

At least get_blog_url() (or whatever it is called) should just be a wrapper for that.

I had the same thought yesterday, but a minor utility of get_blog_url() as it's been written for this ticket is that you can pass in blog_id, similarly to get_site_url() and get_home_url(). Once we land this, we can add support for the post post type in get_post_type_archive_link() by delegating to get_blog_url().

@ericlewis
8 years ago

#19 in reply to: ↑ 17 @ericlewis
8 years ago

Replying to swissspidy:

Minor nitpicking: $this->assertSame( $actual, $expected ); should be $this->assertSame( $expected, $actual );

All nitpicking appreciated :) Updated in attachment:19902.3.diff

#20 @ericlewis
8 years ago

  • Owner changed from chriscct7 to ericlewis
  • Status changed from assigned to accepted

@ericlewis
8 years ago

#21 @ericlewis
8 years ago

#35306 was marked as a duplicate.

#22 @ericlewis
8 years ago

In 36225:

Permalinks: Make get_post_type_archive_link() work for the 'post' post type.

Props jjj.
See #19902.

#23 @ericlewis
8 years ago

Making the existing API work is a first step. When there's consensus on a single responsibility function for the post archive link, we can add that as well.

#24 @swissspidy
8 years ago

#35400 was marked as a duplicate.

#25 @DrewAPicture
8 years ago

In 36300:

Docs: Add a changelog entry to the DocBlock for get_post_type_archive_link() denoting that posts support was added in 4.5.

See [36225]. See #19902.

#26 @ericlewis
8 years ago

  • Owner ericlewis deleted
  • Status changed from accepted to assigned

This ticket was mentioned in Slack in #core by chriscct7. View the logs.


8 years ago

#28 @chriscct7
8 years ago

  • Owner set to ericlewis

#29 follow-up: @jorbin
8 years ago

I think post support for get_post_type_archive_link() accomplishes the goals of the ticket without introducing more functions than are necessary. I suggest closing as fixed.

#30 in reply to: ↑ 29 @johnjamesjacoby
8 years ago

Replying to jorbin:

I think post support for get_post_type_archive_link() accomplishes the goals of the ticket without introducing more functions than are necessary. I suggest closing as fixed.

Seconded. We can always revisit later if the need for blog-specific wrappers arises.

#31 @ericlewis
8 years ago

  • Keywords has-patch has-unit-tests dev-feedback removed
  • Resolution set to fixed
  • Status changed from assigned to closed

As Jorbin noted, get_post_type_archive_link( 'post' ) will now return you the blog index URL. Closing this ticket.

Note: See TracTickets for help on using tickets.