Skip to content

Commit f25da6c

Browse files
committed
learn.jquery.com: Fix PHP warning when empty search results
Previously, the sidebar logic was trying to mark pages as active based on the last result, because that's what the $post variable will be set to from the main loop (have_posts/the_post) in e.g. the search.php or other theme file. Weird as that might be, where it goes wrong is when there is no $post variable, e.g. on a 404, empty category, or empty search results page. Fixes jquery/infrastructure-puppet#31.
1 parent a6d9ea8 commit f25da6c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

themes/learn.jquery.com/sidebar.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<ul>
1313
<?php $chapters = learn_chapter_listing(); ?>
1414
<?php while ( $chapters->have_posts() ) : $chapters->the_post(); ?>
15-
<?php $is_active = ($active_post->ID == $chapters->post->ID) || ($active_post->post_parent == $chapters->post->ID); ?>
15+
<?php $is_active = $active_post && ($active_post->ID == $chapters->post->ID || $active_post->post_parent == $chapters->post->ID); ?>
1616
<li <?php if ($is_active) { echo "class='active'"; } ?>>
1717
<a href="<?php the_permalink(); ?>">
1818
<?php if ( get_post_meta( $post->ID, "icon" ) ) : ?>
@@ -32,7 +32,7 @@
3232
<ul class="sub-chapter">
3333
<?php while ( $sub_chapters->have_posts() ) : $sub_chapters->the_post(); ?>
3434
<?php if ( has_children( $post ) ) { ?>
35-
<?php $is_active = ($active_post->ID == $sub_chapters->post->ID) || ($active_post->post_parent == $sub_chapters->post->ID); ?>
35+
<?php $is_active = $active_post && ($active_post->ID == $sub_chapters->post->ID || $active_post->post_parent == $sub_chapters->post->ID); ?>
3636
<li <?php if ($is_active) { echo "class='active'"; } ?>>
3737
<a href="<?php the_permalink(); ?>">
3838
<?php the_title(); ?>

0 commit comments

Comments
 (0)