term_id, array( 1562, 1563, 1564 ) ) ? 'Social' : $category[0]->name; $args['link'] = NULL; $args['heading'] = 'h1'; } return $args; } /* * Tag page with excerpt and featured image. * See http://www.kriesi.at/support/topic/archive-page-with-excerpt-and-featured-image/ */ add_filter( 'avf_blog_style', 'avia_change_tag_page_layout', 10, 2 ); function avia_change_tag_page_layout( $layout, $context ) { if ( is_tag() ) { $layout = 'single-small'; } return $layout; } /* * Add new class in Social, Twitter, Facebook & LinkedIn posts. * See https://tommcfarlin.com/add-class-to-single-post/ */ add_filter( 'post_class', 'add_social_class' ); function add_social_class( $classes ) { $category = get_the_category(); if ( !empty( $category ) && in_array( $category[0]->term_id, array( 1561, 1562, 1563, 1564 ) ) ) { $classes[] = 'post-entry-social'; } return $classes; } /* * Breadcrumb formatting for social and categories content. * See http://www.kriesi.at/support/topic/how-to-modify-in-child_theme-the-function-avia_breadcrumbs-finished-with-s */ add_filter( 'avia_breadcrumbs_trail', 'avia_change_breadcrumb', 50, 2 ); function avia_change_breadcrumb( $trail, $args ) { if ( is_single() ) { $category = get_the_category(); if ( !empty( $category ) ) { // Correct breadcrumb for Blog, Bloc de notas & Fotoblog single posts: if ( in_array( $category[0]->term_id, array( 982, 978, 976 ) ) && strpos( $trail[1], 'social' ) ) { switch ( $category[0]->term_id ) { case 982: // Blog array_splice( $trail, 1, 2, array( 'Blog' ) ); break; case 978: // Bloc de notas array_splice( $trail, 1, 2, array( 'Bloc de notas' ) ); break; case 976: // Fotoblog array_splice( $trail, 1, 2, array( 'Fotoblog' ) ); } } // Social breadcrumb for Twitter, Facebook & LinkedIn content: elseif ( in_array( $category[0]->term_id, array( 1562, 1563, 1564 ) ) ) { unset ( $trail[2] ); } } } elseif ( is_tag() || is_category( array( 982, 978, 976 ) ) ) { // Posts breadcrumb for Blog, Bloc de notas & Fotoblog categories: array_splice( $trail, 1, 0, array( 'Entradas' ) ); } return $trail; } /* * Adapting content for social networks; and auto generate title if it is empty. */ add_filter( 'wp_insert_post_data', 'review_social_post', 5, 2 ); function review_social_post( $data, $postarr ) { // Count post categories: $categories = array(); if ( !empty( $postarr['post_category'] ) ) { $categories = $postarr['post_category']; } elseif ( !empty( $postarr['tax_input']['category'] ) ) { $categories = $postarr['tax_input']['category']; } $categories = is_array( $categories ) ? array_filter( $categories ) : array( $categories ); $num_categories = count( $categories ); // Review post only for Social, Twitter, Facebook & LinkedIn categories: $num_social_categories = count( array_intersect( array( 1561, 1562, 1563, 1564 ), $categories ) ); if ( $num_social_categories > 0 ) { // Get clean post title: $post_title = trim( str_replace( ' ', ' ', strip_tags( $data['post_title'] ) ) ); // Get clean post content: $post_content = trim( str_replace( ' ', ' ', strip_tags( $data['post_content'] ) ) ); // Auto generate title if it is empty: $isfull_title = false; $title_maxchar = 140 - 28; if ( empty( $post_title ) ) { if ( empty( $post_content ) ) { $post_title = 'Sin título en el morral, sea añejo o fugaz, lo mismo da'; } else { $post_title = substr( $post_content, 0, $title_maxchar ); $post_title = substr( $post_title, 0, strrpos( $post_title, ' ' ) ); $isfull_title = strlen( $post_title ) > strlen( $post_content ); } } elseif ( strlen( $post_title ) > $title_maxchar ) { if ( strpos( $post_content, $post_title ) !== 0 ) { $data['post_content'] = $post_title . '. ' . $data['post_content']; } $post_title = substr( $post_title, 0, $title_maxchar ); $post_title = substr( $post_title, 0, strrpos( $post_title, ' ' ) ); $isfull_title = true; } $data['post_title'] = $isfull_title ? $post_title . '…' : $post_title; // Adapting content for pure social posts: if ( $num_categories == $num_social_categories ) { $content = trim( str_replace( ' ', ' ', strip_tags( $data['post_content'], '