strategic-projects.php
2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
function strategic_crop($content, $maxCharacters, $append = '...', $respectWordBoundaries = false, $stripTags = false)
{
if ($stripTags) {
$content = strip_tags($content);
}
if ($maxCharacters) {
if (mb_strlen($content, 'utf-8') > abs($maxCharacters)) {
$truncatePosition = false;
if ($maxCharacters < 0) {
$content = mb_substr($content, $maxCharacters, null, 'utf-8');
if ($respectWordBoundaries) {
$truncatePosition = strpos($content, ' ');
}
$content = $truncatePosition ? $append . substr($content, $truncatePosition) : $append . $content;
} else {
$content = mb_substr($content, 0, $maxCharacters, 'utf-8');
if ($respectWordBoundaries) {
$truncatePosition = strrpos($content, ' ');
}
$content = $truncatePosition ? substr($content, 0, $truncatePosition) . $append : $content . $append;
}
}
}
return $content;
}
function strategic_projects_shortcode($atts) {
$atts = shortcode_atts(array(
'parent_id' => 0,
), $atts, 'strategic_projects');
$parent_id = intval($atts['parent_id']);
$children = get_pages(array('child_of' => $parent_id));
$output = '';
if(count($children) == 0) {
return "<h1 style='text-align:center'>".__("Coming Soon")."</h1>";
}
foreach ($children as $child) {
if(strlen($child->post_content) > 300) {
$post_content = strategic_crop($child->post_content, 300, '...', true, false);
} else {
$post_content = $child->post_content;
}
$output .= '<div class="strategic-child-page">';
$output .= '<div class="strategic-content"><h2>' . $child->post_title . '</h2>';
$output .= '<div class="strategic-child-page-content">' . strategic_crop($child->post_content, 300, '...', true, false) . '</div></div>';
$output .= '<div class="strategic-read-more-button"><a href="' . get_permalink($child->ID) . '" class="strategic-read-more">Read More</a></div>';
$output .= '</div>';
}
return $output;
}
add_shortcode('strategic_projects', 'strategic_projects_shortcode');