Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created March 18, 2019 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billerickson/33a16f027c048f970f919971ee51eba8 to your computer and use it in GitHub Desktop.
Save billerickson/33a16f027c048f970f919971ee51eba8 to your computer and use it in GitHub Desktop.
<?php
/**
* Customizations to Display Posts
*
* @package CoreFunctionality
* @version 2.0
* @author Bill Erickson <bill@billerickson.net>
* @copyright Copyright (c) 2018, Bill Erickson
* @license GPL-2.0+
*/
class BE_DPS_Customizations {
public function __construct() {
// Layout = editors-choice
add_filter( 'display_posts_shortcode_wrapper_open', array( $this, 'layout_editors_choice_open' ), 10, 2 );
add_filter( 'display_posts_shortcode_output', array( $this, 'layout_editors_choice_item' ), 10, 2 );
add_filter( 'display_posts_shortcode_wrapper_close', array( $this, 'layout_editors_choice_close' ), 10, 2 );
}
/**
* Layout = editors choice, open
* @author Bill Erickson
*/
function layout_editors_choice_open( $output, $atts ) {
if( empty( $atts['layout'] ) || 'editors-choice' !== $atts['layout'] )
return $output;
$classes = array( 'display-posts-listing', 'table', 'table-striped', 'table-small' );
if( !empty( $atts['wrapper_class'] ) )
$classes[] = $atts['wrapper_class'];
$output = '<table class="' . join( ' ', $classes ) . '">';
$output .= '<thead><tr role="row" class="row-1"><th>Brand + Product</th><th>Company Report</th><th>Rating</th></tr></thead>';
$output .= '<tbody>';
return $output;
}
/**
* Layout = editors chocie, single item
* @author Bill Erickson
*/
function layout_editors_choice_item( $output, $atts ) {
if( empty( $atts['layout'] ) || 'editors-choice' !== $atts['layout'] )
return $output;
$output = '<tr>';
$output .= '<td><a href="' . get_permalink() . '">' . get_the_title() . '</a></td>';
$output .= '<td>' . ea_report_link() . '</td>';
$output .= '<td>' . ea_dog_food_rating() . '</td>';
$output .= '</tr>';
return $output;
}
/**
* Layout = editors choice, close
* @author Bill Erickson
*/
function layout_editors_choice_close( $output, $atts ) {
if( empty( $atts['layout'] ) || 'editors-choice' !== $atts['layout'] )
return $output;
$output = '</tbody></table>';
return $output;
}
}
new BE_DPS_Customizations();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment