También te permite en vez de los posts mostrar las pages o los products de Woocommerce
Si en vez de usar un plugin queremos hacerlo a pelo en el functions.php creando nuestro propio shortcode sería:
function lsg_listar_all_posts() {
$html = "";
$args = array("posts_per_page" => 10, "orderby" => "rand");
$posts_array = get_posts($args);
foreach($posts_array as $post) {
$html .= "<h3>" . $post->post_title . "</h3>";
$html .= "<p>" . $post->post_content . "</p><br>";
}
return $html;
}
add_shortcode('listar_all_posts', 'lsg_listar_all_posts');
En $args se pueden pasar muchos más parámetros:
https://www.sitepoint.com/exploring-the-wordpress-get_posts-function/
Para mostrar las páginas sin plugin sería:
function lsg_listar_all_pages() {
$html = "";
$pages = get_pages();
foreach ( $pages as $page ) {
$html .= "<h3>".get_page_link( $page->ID )."</h3>";
$html .= "<h4>".$page->post_title."</h4>";
}
return $html;
}
add_shortcode('listar_all_pages', 'lsg_listar_all_pages');
Más información en:https://developer.wordpress.org/reference/functions/get_pages/

No hay comentarios:
Publicar un comentario