SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2011
    Location
    Northern Ireland
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with custom post types for client website!

    Hi,
    I have searched high and low on google for an answer to this question and haven't found anything that works

    Basically i am developing a client website where I have used the Custom Post Type UI plugin to create a post type called "events". I then have a custom page template called events.php which runs a loop that displays all posts of the type "events". My loop is displayed below:

    Code:
            <?php query_posts('post_type=events&post_status=publish&posts_per_page=5' ); ?>
            <?php if (have_posts ()) : ?>
            <?php while(have_posts()) : the_post(); ?>
    					
              <div class="event">
              <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
              <p><?php the_field('event_date') . the_field('event_time'); ?></p>
                <?php the_excerpt(); ?>
                <a style="color: black; text-decoration: underline;" href="<?php the_permalink(); ?>">Read More...</a>
              </div><!-- end event -->
    			
            <?php endwhile; ?>	
            
              <div id="postsnav"><?php posts_nav_link(); ?></div><!-- end postsnav -->
    
            <?php else : ?>
    			
              <p>Nothing Here!</p>
    				
            <?php endif; ?>
            <?php wp_reset_query(); ?>
    It partly works, as when I navigate to the events page, the 5 most recent events are displayed. However when i click "next page", I simply get a page saying "Nothing here" rather than the next events posts :/

    Does anyone know whats wrong here? It seems to be navigating to /events/page/2 and the title of the page is "page not found". Pulling my hair out here lol :/

  2. #2
    SitePoint Enthusiast
    Join Date
    Dec 2011
    Location
    Northern Ireland
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no one? :/

  3. #3
    SitePoint Addict
    Join Date
    Oct 2008
    Location
    Virtual World is my location
    Posts
    311
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Well if I am not wrong with the little wordpress knowledge that I have you wont be able to achieve pagination through regular query_posts query easily. The workaround would be to use WP_Query. Look for the documentation and they have option which states posts per page and paged which I guess will solve your navigation issue. See if it helps or get back.
    RecipesNext.com - recipes, kitchen queries, videos & more...
    BargainNext.com - coupons / deals / bargains / offers & more...

  4. #4
    SitePoint Enthusiast
    Join Date
    Dec 2011
    Location
    Northern Ireland
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK i have tried loads of things... been looking all over google for an answer... here is my modified loop

    Code:
    <?php
      $type = 'events';
      $args=array(
        'post_type' => $type,
        'post_status' => 'publish',
        'paged' => $paged,
        'posts_per_page' => 4,
        'caller_get_posts'=> 1
      );
      $temp = $wp_query;
      $wp_query = null;
      $wp_query = new WP_Query($args);
    ?>
    
    <?php if($wp_query->have_posts()) : while($wp_query->have_posts()) : $wp_query->the_post(); ?>
      <div class="event">
        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
          <p><?php the_field('event_date'); ?><!--<?php the_field('event_date') . the_field('event_time'); ?>--></p>
            <?php the_excerpt(); ?>
            <a style="color: black; text-decoration: underline;" href="<?php the_permalink(); ?>">Read More...</a>
      </div><!-- end event -->
    <?php endwhile; ?>
      <nav>
        <?php previous_posts_link('&laquo; Newer') ?>
        <?php next_posts_link('Older &raquo;') ?>
      </nav>
    <?php else : ?>
      <p>Nothing Here!</p>
    <?php endif; ?>
    However, still the same problem - the posts display on the page as they should, but when you click the next link it displays "nothing here" instead of the later posts :/

  5. #5
    SitePoint Enthusiast
    Join Date
    Dec 2011
    Location
    Northern Ireland
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK - ive just realised. When the permalinks are set to "default", it works fine.. but when set to %postname% it doesn't work... any ideas?? :/

  6. #6
    SitePoint Addict
    Join Date
    Oct 2008
    Location
    Virtual World is my location
    Posts
    311
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Well I checked the above query with wp_query and it works fine with permalinks or without permalinks. What is the exact issue you are facing? One thing you can try is for your custom post type have query vars = true and then check
    RecipesNext.com - recipes, kitchen queries, videos & more...
    BargainNext.com - coupons / deals / bargains / offers & more...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •