Displaying Posts on a Page where Posts Catergory = Page Name
-
Hey,
Lets get down to brass tax:
- I want to show posts in pages
- I want the posts to be relevant to the page.
- The posts category is also the pages name
I have tried adding the following to a page template after the main loop to show the the posts/news (I presume it is the loop that retrieves a pages content?)
<?php query_posts('category_name=<?php the_title(); ?>&posts_per_page=10'); ?> <!-- Start the Loop. --> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php if ( in_category('<?php the_title(); ?>') ) { ?> <div class="dept-news-post"> <?php } else { ?> <div class="post"> <?php } ?> <!-- Display the Title as a link to the Post's permalink. --> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> <!-- Display the Post's Content in a div box. --> <div class="entry"> <?php the_content(); ?> </div> <!-- Stop The Loop (but note the "else:" - see next line). --> <?php endwhile; else: ?> <!-- The very first "if" tested to see if there were any Posts to --> <!-- display. This "else" part tells what do if there weren't any. --> <p>Sorry, no posts matched your criteria.</p> <!-- REALLY stop The Loop. --> <?php endif; ?>
I’m trying to insert the pages name as the category filter in the query_posts bit.
I can imagine because I’m staring a new loop it forgets the pages name.
Does anyone have any suggestions to make this work? on a different way of doing this?
Perhaps creating a variable within the first loop that is remembered to filter the second? I have no idea but I can imagine its possible.
Any and all help received with thanks!
mtwelve
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Displaying Posts on a Page where Posts Catergory = Page Name’ is closed to new replies.