Creación de dos widgets para simular una entrada cuando se usa el editor avanzado

This commit is contained in:
Manuel Cillero 2017-10-30 19:01:22 +01:00
parent b3c7dfd29a
commit e90481b6a2
2 changed files with 202 additions and 5 deletions

View file

@ -65,7 +65,7 @@ function xf_tag_cloud( $tag_string ) {
* Remove Pingbacks from Recent Comments Widget.
* http://ronangelo.com/remove-pingbacks-on-recent-comments-widget
*/
add_filter( 'widget_comments_args', 'remove_pingbacks_recent_comments' );
add_filter( 'widget_comments_args', 'remove_pingbacks_recent_comments' );
function remove_pingbacks_recent_comments( $array ) {
$array['type'] = 'comment';
return $array;
@ -89,9 +89,9 @@ function avia_same_category_filter( $settings ) {
add_filter( 'avf_title_args', 'fix_single_post_title', 10, 2 );
function fix_single_post_title( $args, $id ) {
$category = get_the_category();
if ( $args['title'] == __( 'Blog - Latest News', 'avia_framework' ) && !empty( $category ) ) {
if ( ! empty( $category ) && is_single() && get_post_type() == 'post' ) {
// Social title for Twitter, Facebook & LinkedIn categories:
$args['title'] = in_array( $category[0]->term_id, array( 1562, 1563, 1564 ) ) ? 'Social' : $category[0]->name;
$args['title'] = in_array( $category[0]->name, array( 'Twitter', 'Facebook', 'LinkedIn' ) ) ? 'Social' : $category[0]->name;
$args['link'] = NULL;
$args['heading'] = 'h1';
}
@ -366,6 +366,197 @@ function publish_social_post( $ID, $post ) {
}
} */
/*
* New widget for Enfold theme. Display the single post header with the slider,
* title and meta info.
*/
add_action( 'widgets_init', function() {
register_widget( 'enfold_post_header_widget' );
});
class enfold_post_header_widget extends WP_Widget {
function __construct() {
parent::__construct(
// Base ID:
'enfold_post_header_widget',
// Widget name will appear in UI:
__( 'Enfold Cille Post Header', 'avia_framework' ),
// Widget description:
array( 'description' => __( 'Display the single post header with the slider, title and meta info', 'avia_framework' ) )
);
}
public function widget( $args, $instance ) {
global $avia_config;
echo $args['before_widget'];
$blog_style = avia_get_option( 'single_post_style', 'single-big' );
$blog_global_style = avia_get_option( 'blog_global_style', '' );
$the_id = get_the_ID();
// Get the current post id, the current post class and current post format:
$url = '';
$current_post = array();
$current_post['the_id'] = $the_id;
$current_post['post_type'] = get_post_type( $current_post['the_id'] );
$current_post['post_class'] = 'post-entry-' . $current_post['the_id'] . ' ' . $blog_style;
$current_post['post_class'] .= $current_post['post_type'] == 'post' ? '' : ' post';
$current_post['post_format'] = get_post_format() ? get_post_format() : 'standard';
$current_post['post_layout'] = avia_layout_class( 'main', false );
// Retrieve slider and title for this post...
$size = strpos( $blog_style, 'big' ) ? strpos( $current_post['post_layout'], 'sidebar' ) !== false ? 'entry_with_sidebar' : 'entry_without_sidebar' : 'square';
if ( ! empty( $avia_config['preview_mode'] ) && ! empty( $avia_config['image_size'] ) && $avia_config['preview_mode'] == 'custom' ) {
$size = $avia_config['image_size'];
}
$current_post['slider'] = get_the_post_thumbnail( $current_post['the_id'], $size );
if ( get_post_meta( $current_post['the_id'], '_avia_hide_featured_image', true ) ) {
$current_post['slider'] = '';
}
$current_post['title'] = get_the_title();
// Now apply a filter, based on the post type... (filter function is located in includes/helper-post-format.php):
$current_post = apply_filters( 'post-format-' . $current_post['post_format'], $current_post );
// Extract the variables so that $current_post['slider'] becomes $slider, $current_post['title'] becomes $title, etc...
extract( $current_post );
// Default link and preview image description:
$link = avia_image_by_id( get_post_thumbnail_id(), 'large', 'url' );
$desc = get_post( get_post_thumbnail_id() );
if ( is_object( $desc ) ) {
$desc = $desc->post_excerpt;
}
$featured_img_desc = $desc != '' ? $desc : the_title_attribute( 'echo=0' );
// Echo preview image:
if ( strpos( $blog_global_style, 'elegant-blog' ) === false ) {
if ( strpos( $blog_style, 'big' ) !== false ) {
if ( $slider ) $slider = "<a href=\"$link\" title=\"$featured_img_desc\">$slider</a>";
if ( $slider ) echo "<div class=\"big-preview $blog_style\">$slider</div>";
}
}
echo '<div class="blog-meta">';
if ( strpos( $blog_style, 'multi' ) !== false ) {
$author_name = apply_filters( 'avf_author_name', get_the_author_meta( 'display_name', $post->post_author ), $post->post_author );
$author_email = apply_filters( 'avf_author_email', get_the_author_meta( 'email', $post->post_author ), $post->post_author );
$link = get_author_posts_url( $post->post_author );
}
echo '</div>';
echo '<header class="entry-content-header">';
$taxonomies = get_object_taxonomies( get_post_type( $the_id ) );
$cats = '';
$excluded_taxonomies = array_merge( get_taxonomies( array( 'public' => false ) ), array( 'post_tag', 'post_format' ) );
$excluded_taxonomies = apply_filters( 'avf_exclude_taxonomies', $excluded_taxonomies, get_post_type( $the_id ), $the_id );
if ( ! empty( $taxonomies ) ) {
foreach ( $taxonomies as $taxonomy ) {
if ( ! in_array( $taxonomy, $excluded_taxonomies ) ) {
$cats .= get_the_term_list( $the_id, $taxonomy, '', ', ', '') . ' ';
}
}
}
if ( strpos( $blog_global_style, 'elegant-blog' ) !== false ) {
$cat_output = '';
if ( ! empty( $cats ) ) {
$cat_output .= '<span class="blog-categories minor-meta">';
$cat_output .= $cats;
$cat_output .= '</span>';
$cats = '';
}
echo strpos( $blog_global_style, 'modern-blog' ) === false ? $cat_output . $title : $title . $cat_output;
echo '<span class="av-vertical-delimiter"></span>';
if ( strpos( $blog_style, 'big' ) !== false ) {
if ( $slider ) $slider = "<a href=\"$link\" title=\"$featured_img_desc\">$slider</a>";
if ( $slider ) echo "<div class=\"big-preview $blog_style\">$slider</div>";
}
$cats = '';
$title = '';
}
echo $title;
echo '<span class="post-meta-infos">';
echo '<time class="date-container minor-meta updated">' . get_the_time( get_option( 'date_format' ) ) . '</time>';
echo '<span class="text-sep text-sep-date">/</span>';
if ( get_comments_number() != '0' || comments_open() ) {
echo '<span class="comment-container minor-meta">';
comments_popup_link( '0 ' . __( 'Comments', 'avia_framework' ),
'1 ' . __( 'Comment' , 'avia_framework' ),
'% ' . __( 'Comments', 'avia_framework' ), 'comments-link',
'' . __( 'Comments Disabled', 'avia_framework' ) );
echo '</span>';
echo '<span class="text-sep text-sep-comment">/</span>';
}
if ( ! empty( $cats ) ) {
echo '<span class="blog-categories minor-meta">' . __( 'in', 'avia_framework' ) . ' ';
echo $cats;
echo '</span><span class="text-sep text-sep-cat">/</span>';
}
echo '<span class="blog-author minor-meta">' . __( 'by', 'avia_framework' ) . ' ';
echo '<span class="entry-author-link">';
echo '<span class="vcard author"><span class="fn">';
the_author_posts_link();
echo '</span></span>';
echo '</span>';
echo '</span>';
echo '</span>';
echo '</header>';
echo $args['after_widget'];
}
}
/*
* New widget for Enfold theme. Display the single post footer with the tags,
* social share links and related posts.
* See http://www.wpbeginner.com/wp-tutorials/how-to-create-a-custom-wordpress-widget/
*/
add_action( 'widgets_init', function() {
register_widget( 'enfold_post_footer_widget' );
});
class enfold_post_footer_widget extends WP_Widget {
function __construct() {
parent::__construct(
// Base ID:
'enfold_post_footer_widget',
// Widget name will appear in UI:
__( 'Enfold Cille Post Footer', 'avia_framework' ),
// Widget description:
array( 'description' => __( 'Display the single post footer with the tags, social share links and related posts', 'avia_framework' ) )
);
}
public function widget( $args, $instance ) {
echo $args['before_widget'];
echo '<footer class="entry-footer">';
if ( has_tag() ) {
echo '<span class="blog-tags minor-meta">';
echo the_tags( '<strong>' . __( 'Tags:', 'avia_framework' ) . '</strong><span> ' );
echo '</span></span>';
}
avia_social_share_links();
echo '</footer>';
echo '<div style="margin-top: 172px;">';
echo get_template_part( '../enfold/includes/related-posts');
echo '</div>';
echo $args['after_widget'];
}
}
/*
* Remove Avia Framework debug information in child theme.
* See http://www.kriesi.at/support/topic/removal-of-theme-debug-info/#post-386207

View file

@ -28,6 +28,7 @@ div .av_one_fourth {
.related_posts {
padding-right: 0;
margin-right: 0px !important;
border-top-width: 0;
}
body.tag .content {
padding-top: 12px;
@ -171,11 +172,12 @@ body.home .content {
.entry-content-wrapper {
line-height: 1.42857;
}
.entry-content-wrapper .post-title,
.entry-content-header .post-title,
#top .flex_column .template-blog .post-title {
color: #ff3300;
text-transform: none !important;
font-size: 41px !important;
line-height: 1em;
color: #ff3300;
}
.entry-content-wrapper h2,
.entry-content-wrapper h3,
@ -298,6 +300,10 @@ footer.entry-footer {
margin-bottom: 30px;
}
/* Comments */
.comment_container h3 {
color: #e9146c;
font-size: 28px;
}
#top .comment_text {
font-size: 16px;
} /*