• Hey guys,

    i got a little own template with an own wp query für displaying custom post type but i don’t get a navigation wenn there are more than X posts per page.

    <?php<br />
    /**<br />
     * Template Name: Schlagzeilen/Sammlung<br />
     *<br />
     */</p>
    <p>get_header(); ?></p>
    <p>		<div id="container"><br />
    			<div id="content" role="main"></p>
    <p>            <h1 class="site-title">Aktuelle Schlagzeilen</h1></p>
    <p><!-- Schlagzeilen --><br />
    <div id="schlagzeilen"><br />
    <h2>Aktuelle Schlagzeilen</h2></p>
    <p><?php<br />
    $schlagzeilen = new WP_Query(array('post_type' => 'os_schlagzeilen', 'posts_per_page' => '4'));<br />
    while ($schlagzeilen->have_posts()) : $schlagzeilen->the_post();<br />
    ?></p>
    <p>			<div class="schlagzeile"><br />
    				<span class="date"><?php echo get_the_date('d.m.Y'); ?></span><br />
    				<h3 class="title-schlagzeile"><a>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h3><br />
    				<?php echo schlagzeile_excerpt(); ?><br />
    			</div></p>
    <p><?php endwhile; wp_reset_query(); ?><br />
    </div></p>
    <p><?php /* Display navigation to next/previous pages when applicable */ ?><br />
    <?php if (  $schlagzeilen->max_num_pages > 1 ) : ?><br />
    				<div id="nav-below" class="navigation"><br />
    					<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'twentyten' ) ); ?></div><br />
    					<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'twentyten' ) ); ?></div><br />
    				</div><!-- #nav-below --><br />
    <?php endif; ?></p>
    <p><!-- // Schlagzeilen --></p>
    <p>			</div><!-- #content --><br />
    		</div><!-- #container --></p>
    <p><?php get_sidebar(); ?><br />
    <?php get_footer(); ?><br />

    whats wrong with my query? sorry i’m not a great programmer..

    thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • All I’ve noticed is this:

    <?php<br />
          $schlagzeilen = new WP_Query(array('post_type' => 'os_schlagzeilen', 'posts_per_page' => '4'));<br />
          while ($schlagzeilen->have_posts()) : $schlagzeilen->the_post();<br />
          ?></p>

    You’ve got a <br /> straight after the <?php

    Thread Starter Nichtschwimmer

    (@nichtschwimmer)

    sorry, something went wrong including the template code, don’t know why.. okay here another try


    <?php
    /**
    * Template Name: Schlagzeilen/Sammlung
    *
    */

    get_header(); ?>

    <div id="container">
    <div id="content" role="main">

    <h1 class="site-title">Aktuelle Schlagzeilen</h1>

    <div class="breadcrumbs">
    <?php
    if(function_exists('bcn_display'))
    {
    bcn_display();
    }
    ?>
    </div>

    <!-- Schlagzeilen -->
    <div id="schlagzeilen-cat">

    <?php
    $schlagzeilen = new WP_Query(array('post_type' => 'os_schlagzeilen', 'posts_per_page' => '5'));
    while ($schlagzeilen->have_posts()) : $schlagzeilen->the_post();
    ?>

    <div class="schlagzeile">
    <span class="date"><?php echo get_the_date('d.m.Y'); ?></span>
    <h3 class="title-schlagzeile">" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></h3>
    <?php echo schlagzeile_excerpt(); ?>
    </div>

    <?php endwhile; wp_reset_query(); ?>
    </div>

    <?php /* Display navigation to next/previous pages when applicable */ ?>
    <?php if ( $schlagzeilen->max_num_pages > 1 ) : ?>
    <div id="nav-below" class="navigation">
    <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'twentyten' ) ); ?></div>
    <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'twentyten' ) ); ?></div>
    </div><!-- #nav-below -->
    <?php endif; ?>

    <!-- // Schlagzeilen -->

    </div><!-- #content -->
    </div><!-- #container -->

    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    You do need to remove that <br /> that’s in your php code. However, I believe you also need to move your wp_reset_query() to someplace after the pagination. Probably right after the if ( $schlagzeilen->max_num_pages > 1 ) conditional code will work fine.

    Thread Starter Nichtschwimmer

    (@nichtschwimmer)

    i tried this, but that doesn’t work too…

    <!-- Schlagzeilen -->
    <div id="schlagzeilen-cat">         
    
    <?php
    $schlagzeilen = new WP_Query(array('post_type' => 'os_schlagzeilen', 'posts_per_page' => '5'));
    while ($schlagzeilen->have_posts()) : $schlagzeilen->the_post();
    ?>
    
    			<div class="schlagzeile">
    				<span class="date"><?php echo get_the_date('d.m.Y'); ?></span>
    				<h3 class="title-schlagzeile"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h3>
    				<?php echo schlagzeile_excerpt(); ?>
    			</div>
    
    </div>
    
    <?php endwhile; ?>
    
    <?php /* Display navigation to next/previous pages when applicable */ ?>
    <?php if (  $schlagzeilen->max_num_pages > 1 ) : ?>
    				<div id="nav-below" class="navigation">
    					<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentyten' ) ); ?></div>
    					<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?></div>
    				</div><!-- #nav-below -->
    
    <?php wp_reset_query(); ?>
    
    <?php endif; ?>
    
    <!-- // Schlagzeilen -->

    This might be what you’re looking for.

    You’ll have to put your div names etc. in

    <?php if ($index_loop->max_num_pages > 1); {?>
    
    <div class="multiple-posts-navigation">
    <span class="multiple-nav-left"><?php next_posts_link('? Older Entries') ?> ? </span>
    <span class="multiple-nav-right">? <?php previous_posts_link('Newer Entries ?') ?></span>
    </div><!--Close multiple-posts-navigation-->
    
    <?php }?>
    
    <?php wp_reset_query(); ?>

    You didn’t have brackets after the if ()

    Thread Starter Nichtschwimmer

    (@nichtschwimmer)

    found a workin’ solution for me ??

    <!-- Schlagzeilen -->
    <div id="schlagzeilen-cat">         
    
    <?php
    	$temp = $wp_query;
    	$wp_query= null;
    	$wp_query = new WP_Query();
    	$wp_query->query('post_type=os_schlagzeilen&post_status=publish&showposts=5'.'&paged='.$paged);
    ?>
    <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
    
    			<div class="schlagzeile">
    				<span class="date"><?php echo get_the_date('d.m.Y'); ?></span>
    				<h3 class="title-schlagzeile"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h3>
    				<?php echo schlagzeile_excerpt(); ?>
    			</div>
    
    <?php endwhile; // End the loop. Whew. ?>
    
    <div class="navigation">
    	<div class="alignleft"><?php next_posts_link('&laquo; &auml;ltere Artikel') ?></div>
     	<div class="alignright"><?php previous_posts_link('neuere Artikel &raquo;') ?></div>
    </div>
    
    <?php $wp_query = null; $wp_query = $temp;?>
    
    </div>
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Navigation and own WP Query’ is closed to new replies.