Trying to modify THE LOOP to create a TOC for a category
-
On the site esl-voices.com (WP 5.2.4; PHP 7.3.11), we use category ‘Guest Plan’ (‘cat’=> 487) for contributed posts, which are displayed separately from the standard Blog, using the menu entry ‘Guest Plans’. Currently, pressing menu entry ‘Guest Plans’ successfullly activates the following Loop[2]:
<?php $temp_post = $post; // Storing the object temporarily $args = array('cat'=> 487); $the_query = new WP_Query($args); // The Loop[2] if($the_query->have_posts()) : while($the_que1Gry->have_posts()) : $the_query->the_post(); get_template_part('content', get_post_format()); endwhile; $post = $temp_post; // Restore the value of $post to the original ?>
We would like to create a table of contents at the beginning of the display.
I’ve attempted to begin building this by prefixing a preliminary Loop[1] (copied from the Standard Loop on
https://developer.www.ads-software.com/reference/classes/wp_query/)
which would extract the titles of the posts, as follows:<?php $temp_post = $post; // Storing the object temporarily $args = array('cat'=> 487); $the_query = new WP_Query($args); // The Loop[1] if($the_query->have_posts()) : echo '<ul>'; while ( $the_query->have_posts()) : $the_query->the_post(); echo '<li>' . get_the_title() . '</li>'; endwhile; echo '</ul>'; // The Loop[2] if($the_query->have_posts()) : while($the_query->have_posts()) : $the_query->the_post(); get_template_part('content', get_post_format()); endwhile; $post = $temp_post; // Restore the value of $post to the original ?>
However, when I do this, pressing ‘Guest Plans’ produces the output:
The site is experiencing technical difficulties.
If I comment out Loop[2], I get the same result. This is surprising since Loop[1] is copied from https://developer.www.ads-software.com/reference/classes/wp_query/.
Can anyone give me hand here?
Thanks in advance.The page I need help with: [log in to see the link]
- The topic ‘Trying to modify THE LOOP to create a TOC for a category’ is closed to new replies.