Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Como añadir Post Relacionados al final del contenido en Genesis

Aunque añadir artículos o post relacionados es una práctica que no gusta a todo el mundo, sí es una pregunta que nos llega frecuentemente, así que…aquí os explicamos como añadirlos como un GRID de 3 columnas al final del contenido:

Añade este código en el archivo functions.php de tu child theme o en tu mu-plugin.

Esta función te permite añadir 3 artículos Relacionados con los tags a los que pertenezca.

// Añadir Post Relacionados 
add_action( 'genesis_after_entry_content', 'tdw_related_posts', 12 );

function tdw_related_posts() { global $do_not_duplicate;

 if ( ! is_singular ( 'post' ) ) { return; }

 $count = 0; $related = ''; $do_not_duplicate = array(); $cats = wp_get_post_categories( get_the_ID() );


 if ( $cats && $count ';
 echo '';
 echo '';
 echo '
'; } function tdw_related_cat_query( $cats, $count ) { global $do_not_duplicate; if ( ! $cats ) { return; } $postIDs = array_merge( array( get_the_ID() ), $do_not_duplicate ); $catIDs = array(); foreach ( $cats as $cat ) { if ( 3 == $cat ) { continue; } $catIDs[] = $cat; } $showposts = 3 - $count; $tax_query = array( array( 'taxonomy' => 'post_format', 'field' => 'slug', 'terms' => array( 'post-format-link', 'post-format-status', 'post-format-aside', 'post-format-quote' ), 'operator' => 'NOT IN' ) ); $args = array( 'category__in' => $catIDs, 'post__not_in' => $postIDs, 'showposts' => $showposts, 'ignore_sticky_posts' => 1, 'orderby' => 'rand', 'tax_query' => $tax_query, ); $related = ''; $cat_query = new WP_Query( $args ); if ( $cat_query->have_posts() ) { while ( $cat_query->have_posts() ) { $cat_query->the_post(); $count++; /*$title = genesis_truncate_phrase( get_the_title(), 35 );*/ $title = get_the_title(); $related .= '
'; $related .= '' . genesis_get_image( array( 'size' => 'related' ) ) . ''; $related .= '
'; $related .= '' . $title . ''; $related .= '
'; $related .= '
'; } } wp_reset_postdata(); $output = array( 'related' => $related, 'count' => $count ); return $output; }

Ahora puedes darle formato a tu gusto en CSS.

.related-posts {
border-top: 1px solid #ccc;
padding-top: 40px;
}

.related-posts-list .one-third {
border: 1px solid #dde5ea;
border-radius: 5px;
box-sizing: border-box;
box-shadow: 2px 1px 10px 0 rgba(0, 0, 0, .1);
}

.related-posts-list .one-third:first-child {
margin-left: 0;
}

a.related-post-title {
color: #333;
font-size: 16px;
 text-decoration: none;
}

.one-copy {
padding: 1.5rem 1.25rem 1.75rem;
}

Si has tenido algún problema añadiendo tus Post Relacionados, contáctanos!



This post first appeared on Taller De Wordpress, please read the originial post: here

Share the post

Como añadir Post Relacionados al final del contenido en Genesis

×

Subscribe to Taller De Wordpress

Get updates delivered right to your inbox!

Thank you for your subscription

×