Make WordPress Core


Ignore:
Timestamp:
10/15/2010 07:44:57 PM (16 years ago)
Author:
nacin
Message:

Custom post type archives, second pass. see #13818.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/link-template.php

    r15817 r15819  
    4040
    4141        // Note that $type_of_url can be one of following:
    42         // single, single_trackback, single_feed, single_paged, feed, category, page, year, month, day, paged
     42        // single, single_trackback, single_feed, single_paged, feed, category, page, year, month, day, paged, post_type_archive
    4343        $string = apply_filters('user_trailingslashit', $string, $type_of_url);
    4444        return $string;
     
    826826
    827827/**
     828 * Retrieve the permalink for a post type archive.
     829 *
     830 * @since 3.1.0
     831 *
     832 * @param string $post_type Post type
     833 * @return string
     834 */
     835function get_post_type_archive_link( $post_type ) {
     836        global $wp_rewrite;
     837        if ( ! $post_type_obj = get_post_type_object( $post_type ) )
     838                return false;
     839
     840        if ( ! is_array( $post_type_obj->rewrite ) || false === $post_type_obj->rewrite['archive'] )
     841                return false;
     842
     843        if ( get_option( 'permalink_structure' ) ) {
     844                $struct = ( true === $post_type_obj->rewrite['archive'] ) ? $post_type_obj->rewrite['slug'] : $post_type_obj->rewrite['archive'];
     845                if ( $post_type_obj->rewrite['with_front'] )
     846                        $struct = $wp_rewrite->front . $struct;
     847                $link = home_url( user_trailingslashit( $struct, 'post_type_archive' ) );
     848        } else {
     849                $link = home_url( '?post_type=' . $post_type );
     850        }
     851
     852        return apply_filters( 'post_type_archive_link', $link, $post_type );
     853}
     854
     855/**
     856 * Retrieve the permalink for a post type archive feed.
     857 *
     858 * @since 3.1.0
     859 *
     860 * @param string $post_type Post type
     861 * @param string $feed Optional. Feed type
     862 * @return string
     863 */     
     864function get_post_type_archive_feed_link( $post_type, $feed = '' ) {
     865        $default_feed = get_default_feed();
     866        if ( empty( $feed ) )
     867                $feed = $default_feed;
     868
     869        if ( ! $link = get_post_type_archive_link( $post_type ) )
     870                return false;
     871        $post_type_obj = get_post_type_object( $post_type );
     872        if ( $post_type_obj->rewrite['feeds'] && get_option( 'permalink_structure' ) ) {
     873                $link = trailingslashit($link);
     874                $link .= 'feed/';
     875                if ( $feed != $default_feed )
     876                        $link .= "$feed/";
     877        } else {
     878                $link = add_query_arg( 'feed', $feed, $link );
     879        }
     880
     881        return apply_filters( 'post_type_archive_feed_link', $link, $feed );
     882}
     883
     884/**
    828885 * Retrieve edit posts link for post.
    829886 *
Note: See TracChangeset for help on using the changeset viewer.