• Hi there,

    I’ve got on my site a news category. It displays on my front page my latest news.

    I want it to display from the 4th news article, and not from the first.

    So it won’t be smthing like this: 1-2-3-4-5-6-7-8-9-10, but rather smthing like this: 4-5-6-7-8-9-10.

    The offset solution is no good.

    Can somebody help me with this ?

Viewing 4 replies - 16 through 19 (of 19 total)
  • this modification calculates the offset for each page ‘manually’ depending on the $paged variable and the ‘post-per-page’ for the ‘news category’:

    <!-- News Articles -->
    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $offset=4; // enter your offset here
    $offset_paged = $offset+($paged-1)*( (arras_get_option('index_count') == 0 ? get_option('posts_per_page') : arras_get_option('index_count')) );
    
    $news_query = array(
    	'cat' => arras_get_option('news_cat'),
    	'paged' => $paged,
    	'offset' => $offset_paged,
    	'showposts' => ( (arras_get_option('index_count') == 0 ? get_option('posts_per_page') : arras_get_option('index_count')) )
    );
    
    	$news_query = array_merge( $news_query , array_filter( $wp_query->query_vars ) );

    tried with my set of posts, seems to work, but could depend on your special settings ??

    PS: just saw it shows the option ‘older entries’ even if you reach the last of the posts – clicking it leads you to a page with just the featured post on top, and a ‘newer entries’ button.

    also: wp_pagenavi plugin shows one page too many ??

    Thread Starter dorinspoaller

    (@dorinspoaller)

    And where does that go? In home.php? From where to where? :)) Sry for all the questions, but I`m a n00b at this.

    If this works I’m gonna send you the real Santa for Christmas :))

    technically, it does not work, because there is one page extra in the page navigation. as @t31os_ stated, the offset parameter interferes with the page navi.
    however, if you have many posts, not many will go to the oldest page of posts, and be confused by a last ’empty’ page.

    the code goes into home.php, into the section which you posted earlier yourself.

    start with finding the line <!-- News Articles --> in home.php.
    add the first few lines of new code after this.
    then add 'offset' => $offset_paged, further down after 'paged' => $paged, – that is all.
    the result should look like this:

    <!-- News Articles -->
    
    <!-- new bit -->
    <?php
    global $offset;
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $offset=4; //enter offset here
    $offset_paged = $offset+($paged-1)*( (arras_get_option('index_count') == 0 ? get_option('posts_per_page') : arras_get_option('index_count')) ); ?>
    <!-- end of first new bit -->
    
    <?php
    $news_query = array(
    	'cat' => arras_get_option('news_cat'),
    	'paged' => $paged,
    	'offset' => $offset_paged,
    	'showposts' => ( (arras_get_option('index_count') == 0 ? get_option('posts_per_page') : arras_get_option('index_count')) )
    );
    
    // if you are a WP plugin freak you can use 'arras_news_query' filter to override the query

    ((if you use the plugin wp_pagenavi, you can edit wp-pagenavi.php and get rid of the ‘extra’ page in the menu – change here in the lines marked with /////////:

    ### Function: Page Navigation: Boxed Style Paging
    function wp_pagenavi($before = '', $after = '') {
    	global $wpdb, $wp_query, $offset;  ////////////
    	if (!is_single()) {
    		$request = $wp_query->request;
    		$posts_per_page = intval(get_query_var('posts_per_page'));
    		$paged = intval(get_query_var('paged'));
    		$pagenavi_options = get_option('pagenavi_options');
    		$numposts = $wp_query->found_posts-$offset; ////////////
    		$max_page=ceil($numposts/$posts_per_page); ///////////////
    		//////     $max_page = $wp_query->max_num_pages; ////////////
    		if(empty($paged) || $paged == 0) {
    			$paged = 1;

    ))

    Thread Starter dorinspoaller

    (@dorinspoaller)

    Dude, you`re a f*****g genius !!! I Love You !!! In a not gay…ish way! ?? It works. Thanks a lot!

Viewing 4 replies - 16 through 19 (of 19 total)
  • The topic ‘PHP Code’ is closed to new replies.