ThemeShaper Forums » Thematic

[closed]

The loop isn't working in a function

(11 posts)
  • Started 10 years ago by neonWired
  • Latest reply from markd
  • This topic is resolved
  1. neonWired
    Member

    have_posts() is returning false.

    function news_page() {
    if (is_page(9)) {
    if ( have_posts() ) {
    while ( have_posts() ) {
    the_post();
    the_title();
    the_time('F jS, Y');
    the_author();
    the_content();
    }
    }
    }
    }

    Posted 10 years ago #
  2. Hi,

    could you please provide some more details!

    Where do you call this function? .. what should be displayed? .. Could you provide a link?

    Chris

    Posted 10 years ago #
  3. neonWired
    Member

    this is the full function and filter. I'm just trying to display posts on a page. Should be simple.

    function news_page() {
    if (is_page(9)) {
    if ( have_posts() ) {
    while ( have_posts() ) {
    the_post();
    the_title();
    the_time('F jS, Y');
    the_author();
    the_content();
    }
    }
    }
    }

    add_filter('the_content','news_page');

    Posted 10 years ago #
  4. This can't work :)

    You are trying to filter the post itself with your loop .. that means the post itself is exchanged against a loop.

    Ok .. that's what I got from your code .. on the page with ID 9 you want to display a loop of posts.

    Question: Which posts should be displayed?

    Chris

    Posted 10 years ago #
  5. neonWired
    Member

    you are correct, i want to display a loop of all posts on page ID 9. Basically the same thing as the default front page. Maybe i'm going about it the wrong way. Should it be an action rather than a filter?

    Posted 10 years ago #
  6. With the current and the next version you need to use a page template. This is a quick draft:

    <?php
    /*
    Template Name: Test Page
    */
    ?>
    <?php
        // calling the theme options
        global $options;
        foreach ($options as $value) {
            if (get_option( $value['id'] ) === FALSE) {
                $$value['id'] = $value['std'];
            } else {
                $$value['id'] = get_option( $value['id'] );
            }
        }
    
        // calling the header.php
        get_header();
    
        // action hook for placing content above #container
        thematic_abovecontainer();
    
    ?>
    
    	<div id="container">
    		<div id="content">
    
    			<?php 
    
                // create the navigation above the content
                thematic_navigation_above();
    
                // calling the widget area 'index-top'
                get_sidebar('index-top');
    
                // action hook for placing content above the index loop
                thematic_above_indexloop();
    
    			$wp_query = new WP_Query();
    			$wp_query->query( array( 'posts_per_page' => get_option( 'posts_per_page' ), 'paged' => $paged ) );
    
    			while ( have_posts() ) : the_post() ?>
    
    				<div id="post-<?php the_ID() ?>" class="<?php thematic_post_class() ?>">
    					<?php thematic_postheader(); ?>
    					<div class="entry-content">
    						<?php thematic_content(); ?>
    
    						<?php wp_link_pages('before=<div class="page-link">' .__('Pages:', 'thematic') . '&after=</div>') ?>
    					</div>
    					<?php thematic_postfooter(); ?>
    				</div><!-- .post -->
    
    				<?php comments_template();
    
    				if ($count==$thm_insert_position) {
    					get_sidebar('index-insert');
    				}
    				$count = $count + 1;
    			endwhile;
    
                // action hook for placing content below the index loop
                thematic_below_indexloop();
    
                // calling the widget area 'index-bottom'
                get_sidebar('index-bottom');
    
                // create the navigation below the content
                thematic_navigation_below();
    
                ?>
    
    		</div><!-- #content -->
    	</div><!-- #container -->
    
    <?php 
    
        // action hook for placing content below #container
        thematic_belowcontainer();
    
        // calling the standard sidebar
        thematic_sidebar();
    
        // calling footer.php
        get_footer();
    
    ?>

    Need to put a couple of things on my list for a future version.

    Chris

    Posted 10 years ago #
  7. .. use the SVN copy of Thematic for this template!

    Chris

    Posted 10 years ago #
  8. neonWired
    Member

    Is there anywhere that explains more about page templates? Surely having to write that much code just to display posts defeats the object of using a framework?

    Posted 10 years ago #
  9. neonWired
    Member

    the above scripts gives me an error thematic_abovecontainer(); is an undefined function?

    Posted 10 years ago #
  10. Get the current SVN copy of Thematic.

    OK .. will create a page template package in the next days.

    Chris

    Posted 10 years ago #
  11. markd
    Member

    Just want to note that the action hook thematic_abovecontainer() works in 0.9.6.1. Thanks Chris!

    Posted 10 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.