My page here: /
is displaying all pages on the site, not just the ones that are associated with this 'Selma' category. Which piece am i missing? Should I be using WP_query instead? I'd like to have this dynamic so that all of category pages show the correct pages associated with their cats.
Putting this in my archive.php code:
<ul>
<?php
$cat = get_query_var('cat');
$PozCat = get_category ($this_category);
$PozCat->id;
query_posts('&post_type=page”.'.$PozCat->id);
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<li><a href="<?php the_permalink();?>"><?php the_title(); ?></a></li>
<p> <?php the_excerpt()?> </p>
<?php endwhile; endif; ?>
</ul>
My page here: https://blackfreedom.proquest/category/civil-rights-and-black-power-movements/activism/selma-demonstrations-and-marches/
is displaying all pages on the site, not just the ones that are associated with this 'Selma' category. Which piece am i missing? Should I be using WP_query instead? I'd like to have this dynamic so that all of category pages show the correct pages associated with their cats.
Putting this in my archive.php code:
<ul>
<?php
$cat = get_query_var('cat');
$PozCat = get_category ($this_category);
$PozCat->id;
query_posts('&post_type=page”.'.$PozCat->id);
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<li><a href="<?php the_permalink();?>"><?php the_title(); ?></a></li>
<p> <?php the_excerpt()?> </p>
<?php endwhile; endif; ?>
</ul>
Share
Improve this question
edited Oct 2, 2020 at 14:42
Joe Kalucki
asked Oct 2, 2020 at 14:10
Joe KaluckiJoe Kalucki
11 bronze badge
2
|
1 Answer
Reset to default 0Resolved using this:
<div>
<ul>
<?php
$current_category = get_queried_object(); ////getting current category
$args = array(
'post_type' => 'page',// your post type,
'orderby' => 'menu_order',
'order' => 'DESC',
'cat' => $current_category->cat_ID // current category ID
);
$the_query = new WP_Query($args);
if($the_query->have_posts()):
while($the_query->have_posts()): $the_query->the_post();
echo '<h2><a href="'.get_the_permalink().'">'.get_the_title().'</a></h2>';
"<p>".the_excerpt()."</p>";
endwhile;
endif;
?>
</ul>
</div>
$this_category
is not defined; try working with:$PozCat = get_category ($cat);
– Michael Commented Oct 3, 2020 at 1:58