• Resolved Batleth

    (@batleth)


    Hello there,

    i am trying to fetch some single post from the Blog without using the Loop. It worked for following:

    <?php $custom = array('numberposts' => 1, 'offset' => 0,);
          get_posts($custom);
    	  ?>

    Now i display the title, excerpt and make us of the permalink. After that i reset the postdata
    <?php wp_reset_postdata(); ?>
    With this code i get always the latest posts from my wordpress. The Problem is i want also the next two posts in a new section of the site (chronological).
    I tried it with numberposts=2 offset 1 but this gives me also the latest post.

    Does anyone know how i have to modify my querry to get it work?

    Short Example of Use Case:
    For example three containers on landing page without Blog.
    Container 1: Article 1 at 5/10/2014
    Container 2: Article 2 at 6/10/2014
    Container 3: Article 3 at 7/10/2014
    and Article 4 at 4/10/2014 shouldn’t be fetched.

    I would use a loop but the containers are all diffrent which would lead to a complete css overwork.

    Thank you in anticipation for your replies ??

Viewing 1 replies (of 1 total)
  • Thread Starter Batleth

    (@batleth)

    I thought a lot and now i have a solution with a foreach loop.
    The Code looks like this:

    <div class="carousel-inner" role="listbox">
         <?php
              $i=0;
    		  $posts = get_posts('numberposts=3');
    		  foreach ($posts as $post ) :setup_postdata( $post);
    	  ?>
            <div class="item <?php if($i==0) echo 'active';?>">
            <?php if (has_post_thumbnail()){
            	$thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full');
    			?>
              <img src="<?=$thumbnail[0];?>" alt="First slide">
              <?php } ?>
              <div class="container">
                <div class="carousel-caption">
                  <h1><?php the_title();?></h1>
                  <p><?php the_excerpt();?></p>
                  <p><a class="btn btn-lg btn-primary" href="<?php the_permalink();?>" role="button">Weiterlesen...</a></p>
                </div>
              </div>
            </div>
    <?php
    $i++;
    endforeach;
    wp_reset_postdata();
    ?>
    		</div>

    The topic can be closed ??

Viewing 1 replies (of 1 total)
  • The topic ‘Fetching specific single posts from Blog’ is closed to new replies.