Dynamically filtering loop where page name equals category
-
Hi All,
I had an idea that if I create a category per page with the same name I could dynamically filter the loop for each page by category, without having to create a separate loop for each page.
My results are not working as I hoped, it returns all of the pages and categories.
Has anyone done this before? Below is the URL to the site and the function…Thanks for the help!
https://www.maggieflaniganstudio.com/mfs/our-studio/
<?php function my_index_loop() { ?> <?php if (is_home()) : ?> <!--Custom stuff for homepage--!> <?php else : ?> <?php $title = the_title(); $page_name = str_replace(" ", "-", $title); $pageslug = $post->post_name; // name of the page (slug) $catslug = get_category_by_slug($pageslug); // get category of the same slug $catid = $catslug->term_id; // get id of this category $this_query= 'cat=' . $catid. ''; ?> <?php $other_query = new WP_Query($this_query);?> <?php while ($other_query->have_posts()): $other_query->the_post(); ?> <div class="middle-block"> <?php the_title(); the_content('Read more...'); ?> </div> <div class="bottom-block"> <div class="quote"> <h3>"Craft is there to sustain the original impulse, and to preserve the momentum" <br />-Stanley Kunitz</h3> </div> </div> <?php endwhile; ?> <?php endif;?> <?php } add_action('thematic_indexloop', 'my_index_loop');
Viewing 10 replies - 1 through 10 (of 10 total)
Viewing 10 replies - 1 through 10 (of 10 total)
- The topic ‘Dynamically filtering loop where page name equals category’ is closed to new replies.