class apartments_related_content
{
private $block_name = 'apartments-related-content';
private $block_title = 'Apartments Related Content';
function __construct()
{
add_action('acf/init', array($this, 'register_acf_block'));
add_filter('acf/settings/save_json', array($this, 'block_cta_acf_json_save_point'), 2);
add_filter('acf/settings/load_json', array($this, 'block_cta_acf_json_load_point'), 31);
}
function register_acf_block()
{
if (function_exists('acf_register_block')) {
acf_register_block(array(
'name' => 'pic-' . $this->block_name,
'title' => __('PIC - ' . $this->block_title),
'description' => __($this->block_title),
'render_callback' => array($this, 'acf_render_callback'),
'category' => 'common',
'icon' => 'screenoptions',
'keywords' => array('unit', 'pricing'),
'enqueue_assets' => function () {
wp_enqueue_style('block-css-' . $this->block_name, get_stylesheet_directory_uri() . '/blocks/' . $this->block_name . '/styles.css');
},
'supports' => array(
'align' => true,
'mode' => false,
'jsx' => true
),
));
}
}
function acf_render_callback($block)
{
?>
<!-- <div class="dark-blue-bg apartments-bussines-direcotry-bg" style="background-color: var(--blue-hover) !important;"> -->
<div class="container">
<h2>Related Content</h2>
<div class="apartment-scl">
<?php
$post_ids = get_field('state_college_living_related_posts');
foreach ($post_ids as $post_id) {
$post_image = get_the_post_thumbnail_url($post_id);
$post_title = get_the_title($post_id);
$post_excerpt = get_the_excerpt($post_id);
$post_link = get_the_permalink($post_id);
?>
<div class="apartment-scl-posts">
<img src="<?php echo $post_image ?>" alt="<?php echo $post_title ?>">
<div class="apartment-scl-posts-content">
<h4><?php echo $post_title; ?></h4>
<p><?php echo $post_excerpt; ?></p>
<a href="<?php echo $post_link ?>" style="color: var(--wp--preset--color--vivid-cyan-blue:) !important;">Read More</a>
</div>
</div>
<?php
}
?>
</div>
</div>
<!-- </div> -->
<?php
}
function block_cta_acf_json_save_point($path)
{
$acf_block_name = "Block - " . $this->block_title;
if ($_POST['acf_field_group']['title'] == $acf_block_name) {
$path = get_stylesheet_directory_uri() . 'blocks/' . $this->block_name . '/acf-json';
}
return $path;
}
function block_cta_acf_json_load_point($paths)
{
unset($paths[0]);
$paths[] = get_template_directory() . 'blocks/' . $this->block_name . '/acf-json';
return $paths;
}
}
$apartments_related_content = new apartments_related_content();