Skip to content

Commit 3bcf148

Browse files
add logic for linking to page/anchor from faq-index
1 parent bb378ea commit 3bcf148

File tree

3 files changed

+173
-12
lines changed

3 files changed

+173
-12
lines changed

src/page_faqs.php

+33-2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
<?php foreach ($topQuestions as $question) : ?>
5656

5757
<li>
58+
<!-- links here will need to go to specific group pages, if not set to anchors -->
59+
<!-- possible bi-direction ACF relationship group is useful here to better query? -->
5860
<a href="#<?php echo (str_replace(' ', '-', strtolower($question->post_title))); ?>"><?php echo $question->post_title ?></a>
5961
</li>
6062

@@ -66,6 +68,7 @@
6668
<?php while( have_rows('featured_areas') ): the_row();
6769

6870
$groups = get_sub_field('groups');
71+
$linkType = get_sub_field('link_type');
6972

7073
?>
7174

@@ -85,11 +88,21 @@
8588
$children = get_children($args);
8689
?>
8790
<li>
91+
<?php if ($linkType == 'to-anchor') : ?>
8892
<h3><a href="#<?php echo (str_replace(' ', '-', strtolower($group->post_title))); ?>"><?php echo $group->post_title ?></a></h3>
93+
<?php elseif ($linkType == 'to-page') : ?>
94+
<h3><a href="<?php echo get_permalink($group->ID); ?>"><?php echo $group->post_title ?></a></h3>
95+
<?php endif; ?>
8996
<p><?php echo $group->summary ?></p>
9097
<ul>
9198
<?php foreach ($children as $child) : ?>
92-
<li><h4><a href="#<?php echo (str_replace(' ', '-', strtolower($child->post_title))); ?>"><?php echo $child->post_title; ?></a></h4></li>
99+
<li>
100+
<?php if ($linkType == 'to-anchor') : ?>
101+
<h4><a href="#<?php echo (str_replace(' ', '-', strtolower($child->post_title))); ?>"><?php echo $child->post_title; ?></a></h4>
102+
<?php elseif ($linkType == 'to-page') : ?>
103+
<h4><a href="<?php echo get_permalink($group->ID); ?>#<?php echo (str_replace(' ', '-', strtolower($child->post_title))); ?>"><?php echo $child->post_title; ?></a></h4>
104+
<?php endif; ?>
105+
</li>
93106
<?php endforeach; ?>
94107
</ul>
95108

@@ -98,7 +111,7 @@
98111
</ul>
99112
</article>
100113
</aside>
101-
114+
<?php if ($linkType == 'to-anchor') : ?>
102115
<?php foreach ($groups as $group) : ?>
103116

104117
<?php
@@ -152,6 +165,8 @@
152165

153166
</details>
154167

168+
<?php echo apply_filters( 'the_content', $group->post_content ); ?>
169+
155170
<?php foreach ($questions as $question) : ?>
156171

157172
<h3 id="<?php echo (str_replace(' ', '-', strtolower($question->post_title))); ?>"><?php echo $question->post_title ?></h3>
@@ -188,6 +203,22 @@
188203

189204

190205
<?php endforeach; ?>
206+
<?php endif; ?>
207+
208+
<?php if ($linkType == 'to-page') : ?>
209+
210+
<h2><?php echo $topGroup->post_title; ?></h2>
211+
212+
<?php foreach ($topQuestions as $question) : ?>
213+
214+
215+
<h3 id="<?php echo (str_replace(' ', '-', strtolower($question->post_title))); ?>"><?php echo $question->post_title ?></h3>
216+
<?php echo apply_filters( 'the_content', $question->post_content ); ?>
217+
218+
219+
<?php endforeach; ?>
220+
221+
<?php endif; ?>
191222

192223
<?php endwhile; ?>
193224
<?php endif; ?>

src/single-faqs-group.php

+127
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
<?php get_header('', array( 'body-classes' => 'faq-page') ); ?>
2+
3+
<main>
4+
5+
<?php while ( have_posts() ) : the_post(); ?>
6+
7+
<header>
8+
9+
<nav class="breadcrumbs">
10+
<a href="/faq">FAQs</a>
11+
</nav>
12+
13+
14+
<h1><?php the_title(); ?></h1>
15+
16+
17+
</header>
18+
19+
<div class="content">
20+
21+
22+
<?php the_content(); ?>
23+
24+
25+
<?php
26+
$args = array(
27+
'post_parent' => $post->ID,
28+
'post_type' => 'faqs-group',
29+
'orderby' => 'menu_order',
30+
'order' => 'ASC'
31+
);
32+
$children = get_children($args);
33+
?>
34+
35+
36+
<?php $questions = get_field('faqs_listing', $post->ID); ?>
37+
38+
<details open>
39+
<summary>Table of Contents</summary>
40+
<ul>
41+
<?php foreach ($questions as $question) : ?>
42+
<li>
43+
<a href="#<?php echo (str_replace(' ', '-', strtolower($question->post_title))); ?>"><?php echo $question->post_title ?></a>
44+
45+
<!-- this will need to also grab sub-groups too if Qs are empty, crawl downward -->
46+
</li>
47+
<?php endforeach; ?>
48+
49+
<?php foreach ($children as $child) : ?>
50+
<li>
51+
<a href="#<?php echo (str_replace(' ', '-', strtolower($child->post_title))); ?>"><?php echo $child->post_title ?></a>
52+
53+
<?php $questions = get_field('faqs_listing', $child->ID); ?>
54+
<?php if ($questions) :?>
55+
<ul>
56+
<?php foreach ($questions as $question) : ?>
57+
<li>
58+
<a href="#<?php echo (str_replace(' ', '-', strtolower($question->post_title))); ?>"><?php echo $question->post_title ?></a>
59+
60+
<!-- this will need to also grab sub-groups too if Qs are empty, crawl downward -->
61+
</li>
62+
<?php endforeach; ?>
63+
</ul>
64+
65+
<?php endif; ?>
66+
67+
</li>
68+
<?php endforeach; ?>
69+
70+
71+
</ul>
72+
73+
</details>
74+
75+
<?php echo apply_filters( 'the_content', get_field('introduction', $group->ID) ); ?>
76+
77+
78+
<?php foreach ($questions as $question) : ?>
79+
80+
<h3 id="<?php echo (str_replace(' ', '-', strtolower($question->post_title))); ?>"><?php echo $question->post_title ?></h3>
81+
<a href="<?php echo get_edit_post_link($question->ID); ?>" class="edit" >[edit]</a>
82+
<?php echo apply_filters( 'the_content', $question->post_content ); ?>
83+
84+
<?php endforeach; ?>
85+
86+
<?php
87+
$args = array(
88+
'post_parent' => $post->ID,
89+
'post_type' => 'faqs-group',
90+
'orderby' => 'menu_order',
91+
'order' => 'ASC'
92+
);
93+
$children = get_children($args);
94+
?>
95+
<?php foreach ($children as $child) : ?>
96+
<h3 id="<?php echo (str_replace(' ', '-', strtolower($child->post_title))); ?>"><?php echo $child->post_title ?></h3>
97+
<?php echo apply_filters( 'the_content', get_field('introduction', $child->ID) ); ?>
98+
99+
<!-- loop through and get all the questions from this subsection -->
100+
<?php $questions = get_field('faqs_listing', $child->ID); ?>
101+
<?php foreach ($questions as $question) : ?>
102+
103+
<h4 id="<?php echo (str_replace(' ', '-', strtolower($question->post_title))); ?>"><?php echo $question->post_title ?></h4>
104+
<a href="<?php echo get_edit_post_link($question->ID); ?>" class="edit" >[edit]</a>
105+
<?php echo apply_filters( 'the_content', $question->post_content ); ?>
106+
107+
108+
<?php endforeach; ?>
109+
110+
<?php echo apply_filters( 'the_content', get_field('closing', $child->ID) ); ?>
111+
112+
113+
<?php endforeach; ?>
114+
115+
<?php echo apply_filters( 'the_content', get_field('closing', $group->ID) ); ?>
116+
117+
118+
119+
120+
</div>
121+
122+
123+
124+
<?php endwhile; // end of the loop. ?>
125+
</main>
126+
127+
<?php get_footer(); ?>

src/style.css

+13-10
Original file line numberDiff line numberDiff line change
@@ -598,52 +598,55 @@ main nav.pagination ul li span.current {
598598
/* right: 0; */
599599
}
600600

601-
.faq-index details {
601+
.faq-index details, .faq-page details {
602602
margin-bottom: 2em;
603603

604604
border: 2px solid var(--vocabulary-neutral-color-lighter-gray);
605605
border-radius: 5px;
606606
}
607607

608-
.faq-index details:open summary {
608+
.faq-index details:open summary, .faq-page details:open summary {
609609
margin-bottom: 1em;
610610
}
611611

612-
.faq-index summary {
612+
.faq-index summary, .faq-page summary {
613613
padding: .2em .5em;
614614

615615
background: var(--vocabulary-neutral-color-lighter-gray);
616616

617617
font-size: 1.2em;
618618
}
619619

620-
.faq-index summary:hover {
620+
.faq-index summary:hover, .faq-page summary:hover {
621621
cursor: pointer;
622622
}
623623

624-
.faq-index summary::marker {
624+
.faq-index summary::marker, .faq-page summary::marker {
625625
font-size: .8em;
626626
}
627627

628628

629-
.faq-index details ul {
629+
.faq-index details ul, .faq-page details ul {
630630
margin-left: 2em;
631631
}
632632

633-
.faq-index details ul li {
633+
.faq-index details ul li, .faq-page details ul li {
634634
line-height: 1.8;
635635
}
636636

637-
.faq-index main .content > h4 {
637+
.faq-index main .content > h4, .faq-page main .content > h4 {
638638
font-family: 'Roboto Condensed';
639639
font-size: 1.4em;
640-
641640
}
642641

643-
.faq-index main p {
642+
.faq-index main p, .faq-page main p {
644643
margin-top: 0;
645644
}
646645

646+
.faq-page .breadcrumbs {
647+
font-family: 'Source Sans Pro';
648+
}
649+
647650

648651
@media (min-width: 1500px) {
649652

0 commit comments

Comments
 (0)