ThemeShaper Forums » Thematic

[closed]

How to disable The Loop if paged > 1

(8 posts)
  • Started 3 years ago by jonnycj
  • Latest reply from helgatheviking
  • This topic is not resolved
  1. jonnycj
    Member

    Hello,

    I am using the following code (thanks again to Gene) to display posts from a specific category underneath static page content. There are a lot of posts so I have them 5 to a page with multiple pages. In order to do this there is the standard thematic index Loop to display the static page content, and a second loop to show the posts within the selected category:

    <div id="content">
    
    		<?php
    		// the action hook creating the index loop ?
                	thematic_indexloop();
    		?>
    
    		<?php $wp_query = null; ?>
    		<?php $wp_query = new WP_Query('category_name=survivorsnews&posts_per_page=5&paged='.$paged ); ?>
                    <?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
    
                    <div id="post-<?php the_ID() ?>" class="<?php thematic_post_class() ?>">
    		<a href="<?php the_permalink() ?>"></a>
    	    	<h3 class="entry-title"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
    				<?php the_excerpt(); ?>
    				<?php thematic_postfooter(); ?>
    			</div><!-- .post -->
    
    			<?php endwhile; ?>
    			<?php	thematic_nav_below(); ?>
    
    			</div><!-- #content -->

    This works great and enables basic pagination so that my posts are displayed across multiple pages.

    I have two questions.

    1) Is it possible to disable the first thematic index Loop on all pages created by this code except page 1, where I want it as an introduction ? I imagine it is something like if $paged >1 then do not show index Loop but my php is just not up to structuring this so it actually works !

    2) Secondly is there a more sophisticated form of thematic_nav_below(); which allows users to see how many pages there are in total and therefore click between them ? (so 20 posts produces 4 pages labeled page 1, page 2, page 3, page 4, as we see say in Google search results).

    Any help would be greatly appreciated

    Jon

    Posted 3 years ago #
  2. don't know about #1, but #2 you are looking for the wp_pagenavi plugin

    Posted 3 years ago #
  3. @jonnycj - i tried to get to grips with question#1, but dont fully understand. if you could break it down further, someone may be able to help.

    as for #2, helga is right. thematic is already to go with wp pagenavi plugin, so just install and you are good to go. in the plugin setting you can disable the stylesheet from loading.

    Posted 3 years ago #
  4. jonnycj
    Member

    Hello guys,

    To try and clarify...

    I have created a page template. I want this page to display the content from a given page as well as the posts from a specified category.

    So I create a new page say 'News' in Wordpress and specify it uses this template.
    Using the following code inside this template file I bring in the page content (loop 1) and the posts (loop 2) - I have relabelled the code for clarity:

    <div id="content">
    
    <?php
    // loop 1 brings in the page content
    thematic_indexloop();
    ?>
    
    //loop 2 brings in 5 posts per page from the category 'survivorsnews'
    <?php $wp_query = null; ?>
    <?php $wp_query = new WP_Query('category_name=survivorsnews&posts_per_page=5&paged='.$paged ); ?>
    <?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
    
    <div id="post-<?php the_ID() ?>" class="<?php thematic_post_class() ?>">
    <a href="<?php the_permalink() ?>"></a>
    <h3 class="entry-title"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
    <?php the_excerpt(); ?>
    <?php thematic_postfooter(); ?>
    </div><!-- .post -->
    
    <?php endwhile; ?>
    <?php	thematic_nav_below(); ?>
    
    </div><!-- #content -->

    This code (from Gene :-)) works very well and enables pagination so that my 20 posts are split over 4 'News' pages with 5 posts per page. Thematic nav below allows users to click between the pages.
    The issue is that whilst I want Loop 1 (the page content) on the first of these four 'News' pages I do not want it on pages 2-4.
    So I had imagined that what I need is to build the code above into a conditional statement which says something along the lines of <if $paged is equal to or greater than 2, display only Loop2 else display Loop 1 and Loop 2>.

    This is what I have not managed to do so far :-) So any help would be hugely appreciated !

    Thanks to both of you for the plugin suggestion I will install it

    Posted 3 years ago #
  5. ok- i think i follow you now. first, though, i am still not sure why you are using thematic_loop() ? what template did you copy to create your new template? i probably would have started w/ a copy of page.php, but if it works, it works.

    what if you wrap thematic_loop in a conditional tag?

    if(!is_paged()){
      thematic_loop();
    }

    http://codex.wordpress.org/Conditional_Tags

    in theory it should now only show on the first page (which is NOT paged), but idk if this will work b/c the 2nd query might be monkeying things up. i usually prefer to use get_posts for a secondary loop just so that i don't mess w/ the query object.

    Posted 3 years ago #
  6. jonnycj
    Member

    You are right Helga, I am not sure why I am using this rather than page.php as a base for the template.
    I have used your code however and it works just like that so I am naturally very happy to start with !
    Now that I look at it page.php is indeed very (very) different and I am wondering what the implications are of me using what was essentially a copy of the index page as a basis for my template. I am certainly not sure how to adjust the code above to fit but I will try and post back.

    Thanks once again.

    Posted 3 years ago #
  7. jonnycj
    Member

    OK so the following amendment to the proper page template does the trick to only display page content on the first 'News' page but there is undoubtably a more elegant/effecient way of doing it using only one instance of if(!is_paged()){} rather than my four !

    <div id="post-<?php the_ID();
    					echo '" ';
    					if (!(THEMATIC_COMPATIBLE_POST_CLASS)) {
    						post_class();
    						echo '>';
    					} else {
    						echo 'class="';
    						thematic_post_class();
    						echo '">';
    					}
    
    	                // creating the post header
    	                if(!is_paged()) {
    					thematic_postheader();}
    
    	                ?>
    
    					<div class="entry-content">
    
    	                    <?php
    	                    if(!is_paged()) {
    	                    the_content(); }
    
    						if(!is_paged()) {
    	                    wp_link_pages("\t\t\t\t\t<div class='page-link'>".__('Pages: ', 'thematic'), "</div>\n", 'number');}
    
    	                    if(!is_paged()) {
    						edit_post_link(__('Edit', 'thematic'),'<span class="edit-link">','</span>'); } ?>
    
    					</div><!-- .entry-content -->
    				</div><!-- #post -->

    Thanks again for the input

    Posted 3 years ago #
  8. you should be able to wrap the whole #post div in the conditional

    if(!is_paged()){
      //copy in all the div's code
    }
    Posted 3 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.