Skip to content

Commit

Permalink
Implemented template tags for since version.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rarst committed Jan 10, 2014
1 parent 4145ac6 commit 6fb045e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
16 changes: 14 additions & 2 deletions archive-wpapi-function.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,25 @@

<h1><?php the_title(); ?></h1>

<section class="content">
<section class="description">
<?php the_excerpt(); ?>
</section>

<section class="long-description">
<?php the_content(); ?>
</section>

<section class="return"><strong>Return:</strong> TODO</section>

<section class="since"><strong>Since:</strong> WordPress TODO</section>
<?php
$since = get_since();
if ( ! empty( $since ) ) :
?>
<section class="since">
<strong>Since:</strong> WordPress
<a href="<?php echo get_since_link( $since ); ?>"><?php echo $since; ?></a>
</section>
<?php endif; ?>

<section class="meta">Used by TODO | Uses TODO | TODO Examples</section>

Expand Down
28 changes: 28 additions & 0 deletions template-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,32 @@ function get_current_version() {
) );

return $version[0];
}

/**
* Retrieve URL to since version archive
*
* @param string $name
*
* @return string
*/
function get_since_link( $name = null ) {

$since_object = get_term_by( 'name', empty( $name ) ? get_since() : $name, 'wpapi-since' );

return empty( $since_object ) ? '' : esc_url( get_term_link( $since_object ) );
}

/**
* Retrieve name of since version
*
* @param int $post_id
*
* @return string
*/
function get_since( $post_id = null ) {

$since_object = wp_get_post_terms( empty( $post_id ) ? get_the_ID() : $post_id, 'wpapi-since', array( 'fields' => 'names' ) );

return empty( $since_object ) ? '' : esc_html( $since_object[0] );
}

0 comments on commit 6fb045e

Please sign in to comment.