File: /home/imensosw/www/imenso.co/webofai/wp-content/themes/webofai_theme-old/single.php
<?php
get_header();
$post_id = get_the_ID();
$author_id = get_post_field('post_author', $post_id);
$thumbnail_id = get_post_thumbnail_id($post_id);
$alt = get_post_meta($thumbnail_id, '_wp_attachment_image_alt', true);
$author_name = get_the_author_meta('display_name', $author_id);
$author_url = get_author_posts_url($author_id);
$excerpt = get_the_excerpt($post_id);
$post_date = get_the_date(' F j, Y', $post_id);
$post_title = get_the_title($post_id);
$author_image = get_field('user_image', 'user_' . $author_id);
$main_title = get_field('main_title', $post_id);
$blog_page = get_field('blog_page', 'options');
$blink_title = \Theme\Helpers::get_key_from_array('link_text', $blog_page);
$blog_page = get_field('blog_page', 'options');
$page_archive = \Theme\Helpers::get_key_from_array('page_archive', $blog_page);
// Get the general settings
$wrapper_styles = get_field('wrapper_styles', $post_id);
$container_styles = get_field('container_styles', $post_id);
$custom_style = '';
if (!empty($wrapper_styles['bg_img']['url'])) {
$custom_style .= '.single-post-wrapper { background-image: url(' . esc_url($wrapper_styles['bg_img']['url']) . ')!important;background-attatchment:fixed!important; }';
}
if (!empty($wrapper_styles['bg_color'])) {
$custom_style .= '.single-post-wrapper { background-color: ' . esc_html($wrapper_styles['bg_color']) . '!important; }';
}
if (!empty($wrapper_styles['padding'])) {
$custom_style .= '@media screen and (min-width: 600px) { .single-post-wrapper { padding: ' . intval($wrapper_styles['padding']['top']) . 'px ' . intval($wrapper_styles['padding']['right']) . 'px ' . intval($wrapper_styles['padding']['bottom']) . 'px ' . intval($wrapper_styles['padding']['left']) . 'px!important; } }';
}
if (!empty($wrapper_styles['margin'])) {
$custom_style .= '@media screen and (min-width: 600px) { .single-post-wrapper { margin: ' . intval($wrapper_styles['margin']['top']) . 'px ' . intval($wrapper_styles['margin']['right']) . 'px ' . intval($wrapper_styles['margin']['bottom']) . 'px ' . intval($wrapper_styles['margin']['left']) . 'px!important; } }';
}
if (!empty($container_styles['bg_img']['url'])) {
$custom_style .= '.single-post-wrapper > .container .right-content.center-content { background-image: url(' . esc_url($container_styles['bg_img']['url']) . ')!important; }';
}
if (!empty($container_styles['bg_color'])) {
$custom_style .= '.single-post-wrapper > .container .right-content.center-content { background-color: ' . esc_html($container_styles['bg_color']) . '!important; }';
}
if (!empty($container_styles['padding'])) {
$custom_style .= '@media screen and (min-width: 600px) { .single-post-wrapper > .container .right-content.center-content { padding: ' . intval($container_styles['padding']['top']) . 'px ' . intval($container_styles['padding']['right']) . 'px ' . intval($container_styles['padding']['bottom']) . 'px ' . intval($container_styles['padding']['left']) . 'px!important; } }';
}
//if (!empty($container_styles['margin'])) {
// $custom_style .= '@media screen and (min-width: 600px) { .single-post-wrapper > .container .right-content.center-content { margin: ' . intval($container_styles['margin']['top']) . 'px ' . intval($container_styles['margin']['right']) . 'px ' . intval($container_styles['margin']['bottom']) . 'px ' . intval($container_styles['margin']['left']) . 'px!important; } }';
//}
if (!empty($container_styles['width'])) {
$custom_style .= '@media screen and (min-width: 600px) { .single-post-wrapper > .container .right-content.center-content { max-width: ' . intval($container_styles['width']) . '%!important; } }';
}
//echo 'a7aa';
//var_dump($wrapper_styles);
//var_dump($container_styles['bg_color ']);
if (!empty($custom_style)) {
echo '<style>' . $custom_style . '</style>';
}
$categories = get_the_category($post_id);
$first_category = '';
$category_url = '';
if (!empty($categories)) {
$first_category = $categories[0];
$category_url = get_category_link($first_category->term_id);
$first_category = $first_category->name;
}
function remove_bsf_rt_marker_dom($html)
{
if (empty($html)) {
return $html;
}
$dom = new DOMDocument();
libxml_use_internal_errors(true);
$dom->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'));
libxml_clear_errors();
$xpath = new DOMXPath($dom);
$nodes = $xpath->query('//*[@id="bsf_rt_marker"]');
foreach ($nodes as $node) {
while ($node->firstChild) {
$node->parentNode->insertBefore($node->firstChild, $node);
}
$node->parentNode->removeChild($node);
}
return $dom->saveHTML();
}
$content = get_post_field('post_content', $post_id);
$blocks = parse_blocks($content);
$toc_block_headlines = null;
foreach ($blocks as $i => $block) {
if ($block['blockName'] === "rank-math/toc-block") {
$toc_block_headlines = $block['attrs']['headings'];
array_splice($blocks, $i, 1);
break;
}
}
$update_content = serialize_blocks($blocks);
$content_without_toc = apply_filters('the_content', $update_content);
$content_without_toc = remove_bsf_rt_marker_dom($content_without_toc);
if (have_posts()): the_post(); ?>
<style>
.container section > .container {
max-width: none;
margin-right: 0;
margin-left: 0;
padding-right: 0;
padding-left: 0;
}
</style>
<div class="single-post-wrapper">
<div class="container">
<div class="center-post-wrapper">
<?php
// Loop through the blocks and find the table of contents block
foreach ($blocks as $i => $block) {
if ($block['blockName'] === "rank-math/toc-block") {
// Get the table of contents block content
$toc_block_headlines = $block['attrs']['headings'];
array_splice($blocks, $i, 1);
?>
<div class="sticky-menu">
<h3
class="sticky-menu-title"><?= __('Table of Contents', 'webofai_theme') ?></h3>
<?php
if (is_array($toc_block_headlines)) { ?>
<ul>
<?php foreach ($toc_block_headlines as $index => $row) {
$title = $row['content'];
$content_id = $row['link']; ?>
<li class="sticky-menu-id"><a
href="<?= $content_id ?>"><?= $title ?></a></li>
<?php } ?>
</ul>
<?php } ?>
</div>
<?php break;
}
}
$update_content = serialize_blocks($blocks);
$content_without_toc = apply_filters('the_content', $update_content);
// Apply the custom filter function to remove the bsf_rt_marker div
$content_without_toc = remove_bsf_rt_marker_dom($content_without_toc);
?>
<div
class="right-content <?= !isset($toc_block_headlines) ? ' center-content ' : ' ' ?>">
<?php if ($first_category): ?>
<a href="<?= $category_url ?>" class="single-link"
target="_blank"><?= $first_category ?></a>
<?php endif; ?>
<?php if ($post_title) { ?>
<h1 class="title headline-2"><?= $post_title ?></h1>
<?php } ?>
<div class="author-date">
<picture class="author-image">
<?php if ($author_image) { ?>
<img src="<?= $author_image['url'] ?>"
alt=" <?= $author_image['alt'] ?> ">
<?php } else {
echo get_avatar($author_id, 150);
} ?>
</picture>
<div class="right-content-info">
<?php if ($author_name) { ?>
<div class="author-name headline-5 same-font">
<?= $author_name ?>
</div>
<?php } ?>
<div class="date-time">
<?php
if ($post_date) { ?>
<div class="date headline-5 same-font">
<?= $post_date ?>
</div>
<?php } ?>
<span class="dot-center"></span>
<div class='form-wrapper'>
<?php echo do_shortcode('[read_meter]'); ?>
</div>
</div>
</div>
</div>
<?php if ($thumbnail_id) { ?>
<picture class="aspect-ratio feature-image-single">
<?php echo \Theme\Helpers::get_post_thumbnail($post_id, 'large') ?>
</picture>
<?php } ?>
<div class="cards-wrapper-menu">
<div class="entry-content">
<?= $content_without_toc; ?>
</div>
</div>
</div>
</div>
</div>
</div>
<?php endif; ?>
<?php
get_footer();