Wordpress custom post fetching

Wordpress By Default array :

<?php  
$args = array(
 'posts_per_page'   => 5,
 'offset'           => 0,
 'category'         => '',
 'category_name'    => '',
 'orderby'          => 'date',
 'order'            => 'DESC',
 'include'          => '',
 'exclude'          => '',
 'meta_key'         => '',
 'meta_value'       => '',
 'post_type'        => 'post',
 'post_mime_type'   => '',
 'post_parent'      => '',
 'author'    => '',
 'post_status'      => 'publish',
 'suppress_filters' => true 
);
$posts_array = get_posts( $args );  
 
?> 
 

Posts with Previous Next Navigation:

<?php
$postlist = get_posts( 'sort_column=menu_order&sort_order=asc' );
$posts = array();
foreach ( $postlist as $post ) {
   $posts[] += $post->ID;
}

$current = array_search( get_the_ID(), $posts );
$prevID = $posts[$current-1];
$nextID = $posts[$current+1];
?>

<div class="navigation">
<?php if ( !empty( $prevID ) ): ?>
<div class="alignleft">
<a href="<?php echo get_permalink( $prevID ); ?>"
  title="<?php echo get_the_title( $prevID ); ?>">Previous</a>
</div>
<?php endif;
if ( !empty( $nextID ) ): ?>
<div class="alignright">
<a href="<?php echo get_permalink( $nextID ); ?>" 
 title="<?php echo get_the_title( $nextID ); ?>">Next</a>
</div>
<?php endif; ?>
</div><!-- .navigation -->

 

 
Share on Google Plus

About Unknown

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment

0 comments:

Post a Comment