-
Notifications
You must be signed in to change notification settings - Fork 0
/
related_single.php
153 lines (102 loc) · 4.07 KB
/
related_single.php
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
$related_posts_acf=get_field('kapcsolodo_cikkek');
$related_posts_acf_external=get_field('kapcsolodo_kulso_cikkek');
if ($related_posts_acf) {
// Delete current post ID from related posts array
$this_id=get_the_ID();
$delete_this=array_search($this_id, $related_posts_acf);
if ($delete_this) {unset($related_posts_acf[$delete_this]);}
?>
<div class="related_posts_single box bbsgrey3 mb20 pb20">
<h4 class="fs12px fmedium ls05 cgrey mb20 ttu">Kapcsolódó</h4>
<?php
$p=1;
foreach ($related_posts_acf as $the_acf_post) {
?>
<h5 class="fs15px mb40 ttn kszoveg item-<?php echo $p; ?>"><a href="<?php echo get_permalink($the_acf_post); ?>"><?php echo get_the_title($the_acf_post); ?></a></h5>
<?php $p++; } ?>
<?php if ($related_posts_acf_external) { ?>
<?php
if (have_rows('kapcsolodo_kulso_cikkek')) {
$p=1;
while (have_rows('kapcsolodo_kulso_cikkek') ) : the_row();
$kulso_cikk_cime=get_sub_field('kulso_cikk_cime');
$kulso_cikk_url=get_sub_field('kulso_cikk_url');
?>
<h5 class="fs15px mb40 ttn kszoveg item-<?php echo $p; ?>"><a href="<?php echo $kulso_cikk_url; ?>"><?php echo $kulso_cikk_cime; ?></a></h5>
<?php $p++; endwhile; ?>
<?php } ?>
<?php } ?>
</div>
<?php
} else {
// Get manually inserted related posts from content by last blockquote HTML tag
$content=get_the_content();
$dom = new DomDocument();
$dom->loadHTML('<?xml encoding="utf-8" ?>' . $content);
$dom->preserveWhiteSpace = false;
$blockquotes = $dom->getElementsByTagName('blockquote');
// If found the blockquote element in the old the_content
if ($blockquotes) {
$related_posts_manually=[];
foreach($blockquotes as $blockquote) {
array_push($related_posts_manually, $dom->saveHTML($blockquote));
}
$related_posts_manually = array_values(array_slice($related_posts_manually, -1))[0];
//echo $related_posts_manually;
//echo "<hr>";
if (strpos($related_posts_manually, 'Kapcsol')!==FALSE) {
//echo strip_tags($related_posts_manually);
$dom_related = new DomDocument();
$dom_related->loadHTML('<?xml encoding="utf-8" ?>' . $related_posts_manually);
//$dom_related->preserveWhiteSpace = false;
$rel_posts = $dom_related->getElementsByTagName('a');
$related_posts_list=[];
foreach($rel_posts as $atag) {
array_push($related_posts_list, $dom_related->saveHTML($atag));
}
//var_dump($related_posts_list);
} else {
// The last blockquote element is not related posts list
}
}
if ($related_posts_list && count($related_posts_list)>0) { ?>
<div class="related_posts_single box bbsgrey3 mb20 pb20">
<h4 class="fs12px fmedium ls05 cgrey mb20 ttu">Kapcsolódó</h4>
<?php
$p=1;
//echo "has related posts";
foreach ($related_posts_list as $the_related_post_link) {
?>
<h5 class="fs15px mb40 ttn kszoveg item-<?php echo $p; ?>"><?php echo $the_related_post_link; ?></h5>
<?php $p++; } ?>
<?php if ($related_posts_acf_external) { ?>
<?php
if (have_rows('kapcsolodo_kulso_cikkek')) {
$p=1;
while (have_rows('kapcsolodo_kulso_cikkek') ) : the_row();
$kulso_cikk_cime=get_sub_field('kulso_cikk_cime');
$kulso_cikk_url=get_sub_field('kulso_cikk_url');
?>
<h5 class="fs15px mb40 ttn kszoveg item-<?php echo $p; ?>"><a href="<?php echo $kulso_cikk_url; ?>"><?php echo $kulso_cikk_cime; ?></a></h5>
<?php $p++; endwhile; ?>
<?php } ?>
<?php } ?>
</div>
<?php } ?>
<?php } ?>
<?php if ($related_posts_acf_external && !$related_posts_acf && !$related_posts_list) { ?>
<div class="related_posts_single box bbsgrey3 mb20 pb20">
<h4 class="fs12px fmedium ls05 cgrey mb20 ttu">Kapcsolódó</h4>
<?php
if (have_rows('kapcsolodo_kulso_cikkek')) {
$p=1;
while (have_rows('kapcsolodo_kulso_cikkek') ) : the_row();
$kulso_cikk_cime=get_sub_field('kulso_cikk_cime');
$kulso_cikk_url=get_sub_field('kulso_cikk_url');
?>
<h5 class="fs15px mb40 ttn kszoveg item-<?php echo $p; ?>"><a href="<?php echo $kulso_cikk_url; ?>"><?php echo $kulso_cikk_cime; ?></a></h5>
<?php $p++; endwhile; ?>
<?php } ?>
</div>
<?php } ?>