<?php
/**
 * Custom template tags for Femina
 *
 * @package Femina
 * @since Femina 1.0
 */

if ( ! function_exists( 'femina_posted_on' ) ) :
/**
 * Print HTML with meta information for the current post-date/time and author.
 *
 * @since Femina 1.0
 */
function femina_posted_on() {
	if ( is_sticky() && is_home() && ! is_paged() ) {
		echo '<span class="featured-post">' . __( 'Sticky', 'femina' ) . '</span>';
	}

	// Set up and print post meta information.
	print(__('By ', 'femina'));
	printf( '<span class="byline"><a href="%1$s" rel="author">%2$s</a></span>',
		esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
		get_the_author()
	);
	printf( '<span><a href="%1$s" rel="bookmark"><time class="entry-date" datetime="%2$s">%3$s</time></a></span>',
		esc_url( get_permalink() ),
		esc_attr( get_the_date( 'c' ) ),
		esc_html( get_the_date() )
	);	
}
endif;

if ( ! function_exists( 'femina_excerpt_more' ) && ! is_admin() ) :
/**
 * Replaces "[...]" (appended to automatically generated excerpts) with ...
 * and a Continue reading link.
 *
 * @since Femina 1.0
 *
 * @param string $more Default Read More excerpt link.
 * @return string Filtered Read More excerpt link.
 */
function femina_excerpt_more( $more ) {
	if ( ! is_single()){
		$link = sprintf( '<a href="%1$s" class="more-link">%2$s</a>',
		esc_url( get_permalink( get_the_ID() ) ),
			/* translators: %s: Name of current post */
			sprintf( __( 'More %s <span class="meta-nav">&rarr;</span>', 'femina' ), '<span class="screen-reader-text">' . get_the_title( get_the_ID() ) . '</span>' )
		);
	return ' &hellip; ' . $link;
	}
}
add_filter( 'excerpt_more', 'femina_excerpt_more' );
endif;


/**
 * Filter the except length to 20 characters.
 *
 * @param int $length Excerpt length.
 * @return int (Maybe) modified excerpt length.
 */
function femina_excerpt_length( $length ) {
   return 20;
}

add_filter( 'excerpt_length', 'femina_excerpt_length', 999 );

