ThemeShaper Forums » Thematic

[closed]

Filtering blog posts by category

(5 posts)
  • Started 3 years ago by tg_harris
  • Latest reply from tg_harris
  • This topic is not resolved
  1. OK, seriously people, I need help.

    I know just enough PHP to get into trouble. My new commercial blog concept has a "news" page and a "product reviews" page, both based on the Thematic Blog page filtered by post category: "news" and "reviews" respectively.

    I created new News Page and Reviews Page templates like so:


    /**
    Template Name: News Page
    *
    * This template allows you to display the latest posts marked "news".
    *
    */
    ...
    ?>

    The reviews page is coded similarly. The first problem I found is that when I created these new template pages, naming them template-page-newspage.php and template-page-newspage.php, the new templates did not show up in the drop-down list of templates in the "Edit Page" page.

    Why are the new page templates not available?

    Next, on each of the new template pages I replaced the standard thematic_indexloop() call with a call to a custom loop with a category filter, e.g. news_page_indexloop()
    that calls this in functions.php


    // Create a new indexloop function for the News page template.
    function news_page_indexloop() {
    if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <h1><?php the_title(); ?></h1>
    <?php the_content(); ?>
    <?php endwhile; else: endif; ?>
    <?php query_posts(‘category_name=news&post_status=publish,future’);?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <h2>”><?php the_title(); ?></h2>
    <?php the_content(); ?>
    <?php endwhile; else: endif;
    }

    Which brings me to my second problem: they break my functions.php with an unexpected "=" in the query_posts line, so I have to comment them out. The code seems solid, where did I mess up?

    I can't seem to figure out why these problems are occuring. Can anyone help me figure this out?

    Posted 3 years ago #
  2. OK, so I think I don't need special functions based on what I learned here:

    http://forums.themeshaper.com/topic/using-template-page-blogphp-to-show-specific-categories

    But still, the new template pages are not recognized.

    What am I doing wrong?

    Posted 3 years ago #
  3. it should be working. the template is included (first level) of your child theme?
    in your first post, you miss the opening "<?php" tag in your example. check that.

    <?php
    /**
     * Template Name: My New Template
     */
    ?>

    otherwise, this should be working

    Posted 3 years ago #
  4. I tried a solution I found on Elite Freelancing.com: Activate a different theme--I used Thematic--then switch back to my new theme. Wordpress found the new page templates.

    My reviews page template is working exactly as I want it to. But my news page template still comes up as the old blog page, despite identical coding as the reviews page, save for the search criteria:


    template-page-newspage.php

    <snip>
    <?php
    $wp_query = new WP_Query();
    $wp_query->query( array(
    'category_name' => 'news',
    'posts_per_page' => get_option( 'posts_per_page' ),
    'paged' => $paged ) );
    $more = 0;
    ?>
    </snip>

    template-page-reviewspage.php

    <snip>
    <?php
    $wp_query = new WP_Query();
    $wp_query->query( array(
    'category_name' => 'reviews',
    'posts_per_page' => get_option( 'posts_per_page' ),
    'paged' => $paged ) );
    $more = 0;
    ?>
    </snip>

    Can anyone see what I'm doing wrong? Can I also search by tag?

    Thank you.

    Posted 3 years ago #
  5. DERP!

    I tried changing the read settings so "news" is not my "posts" page. It works better now.

    Posted 3 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.