The file WPPostsWide.php was placed in the community/library/TRN/XenWord/Model directory.
PHP:
<?php
/**
* Filename: WPPostsWide.php
* Author: LPH
*/
class TRN_XenWord_Model_WPPostsWide extends XenForo_Model {
public static function getHtml() {
define( 'WP_USE_THEMES', false );
define( 'DOCUMENT_ROOT', $_SERVER['DOCUMENT_ROOT'] );
// Change the path to the correct location
require( DOCUMENT_ROOT . '/wp-blog-header.php' );
echo '<div class="titleBar"><h1>Latest Articles</h1></div>';
$wp_args = array(
'numberposts' => '5',
'offset' => 0,
'post_type' => 'post',
'post_status' => 'publish'
);
$recentPosts = wp_get_recent_posts( $wp_args );
echo '<div class="recentPosts-container">';
foreach ( $recentPosts as $recentPost ) {
$wpPostThumbnail = get_the_post_thumbnail( $recentPost['ID'], array( 100, 100) );
if ( empty( $wpPostThumbnail ) ) {
echo '<div class="recentPosts">';
echo '<div class="recentPosts-title">';
echo "<h4><a href='" . esc_url( get_permalink( $recentPost['ID'] ) ) . "'>" . $recentPost['post_title'] . '</a></h4>';
echo '</div></div>';
} else {
echo '<div class="recentPosts"><div class="recentPosts-title">';
echo '<div class="wide-thumbnail">' . $wpPostThumbnail . '</div>';
echo "<h4><a href='" . esc_url( get_permalink( $recentPost['ID'] ) ) . "'>" . $recentPost['post_title'] . '</a></h4><br />';
echo '</div></div>';
}
}
wp_reset_query();
echo '</div>';
}
}
// End WPPosts.php
This CSS was placed in the extra.css template.
Code:
div.recentPosts-title {
margin-top: 10px;
}
div.recentPosts-container {
display: flex;
overflow: hidden;
}
div.recentPosts {
width: 20%;
padding: 10px;
text-align: center;
border: 1px solid lightblue;
margin: 10px;
background-color: aliceblue;
}
div.wide-thumbnail {
overflow: hidden;
}