Support » Fixing WordPress » Page of posts template for Twenty Ten with Read more

  • Resolved shanafourde

    (@shanafourde)


    I want to create a page of posts using Twenty Ten that uses a different header than the rest of the site. I created a second header file “header-posts.php” for this purpose. No problem there.

    Then on the page of posts I want to have my posts’ summaries listed with the “Read More” link. That is where I am having the problem. I either get an error or my page of posts lists the full article.

    Can someone help?

    This is my current code which is giving me an error:

    <?php
    /**
     * Template Name: Page of Posts
     */
    get_header(posts); ?>
    
    		<div id="container">
    			<div id="content" role="main">
    
    			<?php
    			/* Run the loop to output the posts.
    			 * If you want to overload this in a child theme then include a file
    			 * called loop-index.php and that will be used instead.
    			 */
    			 get_template_part( 'loop', 'index' );
    			?>
    			</div><!-- #content -->
    		</div><!-- #container -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    This is the error I get:
    Warning: strpos() [function.strpos]: Offset not contained in string. in /home/foren5/public_html/dev/wp-includes/compat.php on line 55

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter shanafourde

    (@shanafourde)

    I have looked at the WordPress codex trying to solve my problem. I tried this code:

    <?php
    /**
     * Template Name: Page of Posts
     *
     */
    
    get_header(posts); ?>
    
    		<div id="container">
    			<div id="content" role="main">
    
    <?php
    $type = 'post';
    $args=array(
      'post_type' => $type,
      'post_status' => 'publish',
      'paged' => $paged,
      'posts_per_page' => 20,
      'caller_get_posts'=> 1
    );
    $temp = $wp_query;  // assign orginal query to temp variable for later use
    $wp_query = null;
    $wp_query = new WP_Query($args);
    ?>
    <?php
    
     get_template_part( 'loop', 'index' );?>
    
    			</div><!-- #content -->
    		</div><!-- #container -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    But it just gives me a list of all my posts, they aren’t the intros with “read more”.

    From WordPress 3.0 you don’t need to create a new header template file to just to show a different image. All you need to do is to specify the header you want in the pages ‘Featured Image’ section (found under the ‘Publish’ and ‘Page Attributes’ meta boxes on the edit pages screen).

    Just makes it easy to set up any number of custom headers for each post/page you want without having to create header.php theme template files manually.

    Thread Starter shanafourde

    (@shanafourde)

    It’s more than just changing the header image. I have modified the theme some. On my “pages” I don’t have the horizontal navigation bar; I use a widget for navigation. However for the “posts” I want the top horizontal navigation bar. There are some other differences as well. That’s why I have a different header template.

    Thread Starter shanafourde

    (@shanafourde)

    ok I think I figured it out.

    <?php
    /**
     * Template Name: Page of Posts
     */
    
    get_header(posts); ?>
    
    		<div id="container">
    			<div id="content" role="main">
    
    <?php
    $cat = '';
    $showposts = -1; // -1 shows all posts
    $do_not_show_stickies = 1; // 0 to show stickies
    $args=array(
    
       'category__in' => $cat,
    
       'showposts' => $showposts,
    
       'caller_get_posts' => $do_not_show_stickies
    
       );
    
    $my_query = new WP_Query($args); 
    
    ?>
    
    	<?php if( $my_query->have_posts() ) : ?>
    		<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    
    			<?php
    
    			//necessary to show the tags 
    
    			global $wp_query;
    
    			$wp_query->in_the_loop = true;
    
    			?>
    
    <?php
    global $more;
    $more = 0;
    ?>
    
    <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    
    					<h1 class="entry-title"><?php the_title(); ?></h1>
    
    					<div class="entry-meta">
    						<?php twentyten_posted_on(); ?>
    					</div><!-- .entry-meta -->
    
    				<div class="entry-content">
    
    					<?php the_content('<div id=readmore>Read more...</div>'); ?>
    
    				</div>
    
    				<!--<p class="postmetadata"><?php the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?>  <?php comments_popup_link('No Comments ?', '1 Comment ?', '% Comments ?'); ?></p>-->
    
    			</div>
    
    		<?php endwhile; ?>
    
    	<?php else : ?>
    
    		<h3 class="center">Not Found</h3>
    
    		<p class="center">Sorry, but you are looking for something that isn't here.</p>
    
    		<?php get_search_form(); ?>
    
    	<?php endif; ?>
    
    			</div><!-- #content -->
    		</div><!-- #container -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    It isn’t pretty but it seems to work.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Page of posts template for Twenty Ten with Read more’ is closed to new replies.