Posent-nos en situació. Tenim una pàgina estàtica o feta a codi, amb un WordPress dins la carpeta /blog.
La pàgina està realitzada amb PHP-HTML5 i Bootstrap.
Per a afegir les darreres entrades a la pàgina principal d’aquesta plataforma, únicament cal seguir els següents passos:
- “Cridar” el fitxer wp-load.php
- Cridem també a la classe global wpdb de WordPress
- Creem una nova “query”, pillant els últims 3 posts
- Omplim mitjançant bootstrap i les funcions: the_title (el títol del post) , the_post_thumbnail (la imatge destacada) , the_permalink() (enllaç de l’entrada).
I voilà! Ja tenim les entrades maquetades en la nostra pàgina externa.
<?php require_once "blog/wp-load.php"; global $wpdb; $the_query = new WP_Query( 'posts_per_page=3' ); ?> <section class="section-lg" id="section-see-features"> <div class="text-center"> <hr class="divider divider-sm"> <h2>Últimos artículos del blog</h2> <br /> </div> <div class="container text-center"> <div class="row row-50 justify-content-center"> <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?> <div class="col-lg-4 col-md-7"> <div class="img-thumbnail-variant-4"> <figure><a role="Entrada blog" href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><img loading="lazy"src="<?php the_post_thumbnail(); ?>" alt="<?php the_title(); ?>"></a><a role="Entrada Blog" href="<?php the_permalink() ?>" class="caption-abs"> <?php the_title(); ?></a> </figure> </div> </div> <?php endwhile; wp_reset_postdata(); ?> </div> </div> </section>