Skip to content

Commit

Permalink
Merge pull request #2 from thenewinquiry/1.0.8
Browse files Browse the repository at this point in the history
#19 Added Co-authors Plus support
  • Loading branch information
misfist authored Apr 11, 2017
2 parents 51729d4 + c6d1936 commit 3a8e6ba
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 16 deletions.
22 changes: 13 additions & 9 deletions includes/class-tni-core-shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public function margin_right_shortcode( $attr, $content = null ) {
*
* @since 1.0.6
*
* @todo Add template loader to allow template to be modified in the theme
* @todo Add template loader to allow template to be modified in the theme
*
* @uses Jetpack_RelatedPosts
* @link https://jetpack.com/support/related-posts/customize-related-posts/
Expand All @@ -202,24 +202,28 @@ public function jetpack_related_posts_shortcode( $atts ) {
);

if ( $related ) {
global $post;
foreach ( $related as $result ) {
$related_post = get_post( $result[ 'id' ] );
$thumb = get_the_post_thumbnail( $related_post->ID, 'thumbnail' );
$category = get_the_category( $related_post->ID )[0];
$author = get_the_author_meta( 'display_name', $related_post->post_author );
$author_url = get_author_posts_url( $related_post->post_author );
$subhead = get_post_meta( $related_post->ID, 'post_subhead', true );
$post = get_post( $result[ 'id' ] );
setup_postdata( $post );

$thumb = get_the_post_thumbnail( $post->ID, 'thumbnail' );
$category = get_the_category( $post->ID )[0];
$author = get_the_author_meta( 'display_name', $post->post_author );
$author_url = get_author_posts_url( $post->post_author );
$subhead = get_post_meta( $post->ID, 'post_subhead', true );
if ( !$subhead ) {
$subhead = get_the_excerpt( $related_post->ID );
$subhead = get_the_excerpt( $post->ID );
}
$permalink = get_permalink( $related_post->ID );
$permalink = get_permalink( $post->ID );

ob_start();

include( TNI_CORE_DIR . '/templates/related-posts.php' );

$related_html .= ob_get_clean();
}
wp_reset_postdata();
}
}
return '<div class="related-posts post-wrapper">' . $related_html . '</div>';
Expand Down
38 changes: 38 additions & 0 deletions includes/template-tags.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/**
* Tni Core Template Tags
*
* @package Tni_Core
* @subpackage Tni_Core\Includes
* @since 1.0.8
* @license GPL-2.0+
*/

/**
* Display Autbor(s)
* If Co-authors Plus is active, return co-author links
*
* @since 1.0.8
*
* @uses coauthors_posts_links()
* @uses get_author_posts_url()
* @uses get_the_author()
*
* @return string
*/
function tni_core_authors() {

if( function_exists( 'coauthors_posts_links' ) ) {
$author_string = coauthors_posts_links( ', ', __( ' and ', 'tni' ), '<span class="author vcard">' . __( 'By ', 'tni' ), '</span>', false );
} else {
$author_string = sprintf( '<span class="author vcard">%s<a class="url fn n" href="%s" title="%s" rel="author">%s</a></span>',
__( 'By ', 'tni' ),
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
esc_attr( sprintf( esc_html__( 'View all posts by %s', 'tni' ),
get_the_author() ) ),
esc_html( get_the_author() )
);
}

return '<span class="meta-author"> ' . $author_string . '</span>';
}
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: misfist
Tags: custom
Requires at least: 4.7
Tested up to: 4.7.2
Version: 1.0.7
Version: 1.0.8
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand All @@ -22,6 +22,9 @@ This section describes how to install the plugin and get it working.

== Changelog ==

= 1.0.8 April 11, 2017 =
* Added Co-authors Plus support to Related Posts

= 1.0.7 April 7, 2017 =
* Removed unused featured content option page
* Removed form processor
Expand Down
15 changes: 11 additions & 4 deletions templates/related-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,33 @@
<div class="post-column clearfix">
<article id="<?php get_the_ID(); ?>" class="related-post type-post">
<figure class="post-thumbnail">
<a href="<?php echo esc_url( $permalink ); ?>" rel="bookmark">
<?php echo $thumb; ?>
<a href="<?php echo esc_url( the_permalink() ); ?>" rel="bookmark">
<?php if( has_post_thumbnail( $post ) ) : ?>
<?php the_post_thumbnail( 'thumbnail' ); ?>
<?php endif; ?>
</a>
</figure>
<div class="entry-meta">
<span class="meta-category"><a href="<?php echo esc_url( get_category_link( $category->term_id ) ); ?>" rel="category tag"><?php esc_html_e( $category->name ); ?> </a></span>
</div>
<h2 class="entry-title">
<a href="<?php echo esc_url( $permalink ); ?>" rel="bookmark">
<?php echo esc_attr( $related_post->post_title ); ?>
<a href="<?php echo esc_url( the_permalink() ); ?>" rel="bookmark">
<?php the_title(); ?>
</a>
</h2>
<div class="entry-meta">
<?php if( function_exists( 'tni_core_authors' ) ) : ?>
<?php echo tni_core_authors(); ?>
<?php else : ?>
<span class="meta-author">
<span class="author vcard">
<?php _e( 'By', 'tni-core' ); ?> <a href="<?php echo esc_url( $author_url ); ?>" class="url fn n">
<?php echo esc_attr( $author ); ?>
</a>
</span>
</span>
<?php endif; ?>

</div>
<div class="entry-content entry-excerpt clearfix">
<?php echo esc_html_e( $subhead ); ?>
Expand Down
5 changes: 3 additions & 2 deletions tni-core-functionality.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Text Domain: tni-core
* Domain Path: /languages
*
* Version: 1.0.7
* Version: 1.0.8
*
* @package Tni_Core_Functionality
*/
Expand All @@ -26,6 +26,7 @@
define( 'TNI_CORE_DIR_URL', plugin_dir_url( __FILE__ ) );

require_once( 'includes/helpers.php' );
require_once( 'includes/template-tags.php' );

// Load plugin class files
require_once( 'includes/class-tni-core.php' );
Expand All @@ -44,7 +45,7 @@
* @return object Tni_Core
*/
function Tni_Core() {
$instance = Tni_Core::instance( __FILE__, '1.0.7' );
$instance = Tni_Core::instance( __FILE__, '1.0.8' );

return $instance;
}
Expand Down

0 comments on commit 3a8e6ba

Please sign in to comment.