Opened 14 years ago
Closed 10 years ago
#19902 closed feature request (fixed)
blog_url() and get_blog_url() template tags
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 4.5 | Priority: | normal |
| Severity: | normal | Version: | 3.3.1 |
| Component: | Permalinks | Keywords: | |
| Focuses: | Cc: |
Description (last modified by )
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)
Change History (35)
#2
in reply to:
↑ 1
;
follow-up:
↓ 8
@
14 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.
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()
#4
@
14 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
@
13 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.
#7
@
12 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
@
12 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()
#10
@
11 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:
↓ 12
@
11 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
@
11 years ago
Replying to SergeyBiryukov:
This sounds similar to how is_front_page() works, so I'd suggest
get_front_page_url()andfront_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_blogsfor 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
@
10 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
#15
@
10 years ago
- Keywords has-patch has-unit-tests added; needs-patch needs-unit-tests removed
- Removing
the_blog_url()for the moment, which echoes the URL. Do we want this?get_site_url()andget_home_url()don't have echoing equivalents. - Added two unit tests.
- Fixed up docs.
#16
@
10 years ago
- Keywords dev-feedback added
Let's circle back to function naming. These options are on the table:
- Since we have get_post_type_archive_link() for custom post types, perhaps
get_post_archive_link()? get_blog_index_url()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:
↓ 18
↓ 19
@
10 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
@
10 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().
#19
in reply to:
↑ 17
@
10 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
@
10 years ago
- Owner changed from chriscct7 to ericlewis
- Status changed from assigned to accepted
#23
@
10 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.
This ticket was mentioned in Slack in #core by chriscct7. View the logs.
10 years ago
#29
follow-up:
↓ 30
@
10 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
@
10 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.
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.