xarxaprod-wp-theme/template-parts/section-featured.php

56 lines
1.6 KiB
PHP

<?php
/**
* Template part for displaying featured posts or "ajuts" and widgets
*
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/
*
* @package Xarxaprod_theme
*/
?>
<aside id="destacats" class="home-featured home-destacats">
<?php
// Detect plugin. For use on Front End only.
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
// check for plugin using plugin name
if ( is_plugin_active( 'xarxaprod-wp-plugin/xarxaprod-wp-plugin.php' ) ) {
//plugin is activated do
?>
<header>
<h2> <?php echo esc_html__('Destacats', 'xarxaprod'); ?></h2>
</header>
<main id="destacats" class="xarxaprod-destacats xarxaprod-featured">
<?php
// https://developer.wordpress.org/reference/functions/get_posts/
// https://www.advancedcustomfields.com/resources/true-false/
$featured_query = new WP_Query(
array(
'post_type' => array( 'post', 'xarxaprod-ajut' ),
'posts_per_page' => '4',
'meta_query' => array(
array(
'key' => 'os_home_show',
'value'=> '1',
)
)
) );
?>
<?php if ( $featured_query->have_posts() ) : ?>
<?php while ( $featured_query->have_posts() ) : $featured_query->the_post(); ?>
<?php get_template_part( 'template-parts/section', 'eachpost' ); ?>
<?php endwhile;//end of the loop ?>
<?php wp_reset_postdata(); ?>
<?php else : //if no post in query ?>
<p class="no-content"></p>
<?php endif; //end query ?>
</main>
<?php } //closing if is_plugin_active ?>
</aside>