WordPress.org

Ready to get started?Download WordPress

Forums

Apply the ID to element from query_posts just once (3 posts)

  1. Chris Demetriad
    Member
    Posted 2 years ago #

    I have this second query and I can't use pagination as I am using another query before which extracts just one post from the same category but styled differently.

    Now, with the second query I use offset=1 so I won't have the last post twice, therefore my WP-PageNavi doesn't work as expected anymore.

    [Code moderated as per the Forum Rules. Please use the pastebin]

    What I've done is to add an id to the containing div:

    id="<?php if ($wp_query->current_post < 1) echo "the-first-post"; ?>"

    And this applies that id which I can hide with CSS but the problem is, the first containing element from the second page gets, obviously, the same ID.

    Is there any possibility to make it somehow to apply the ID just once? This way I will get this pagination issue sorted. Or.. to apply the id IF the page doesn't contain "page" in the URL? That might be the solution.

    Thank you.

  2. Chris Demetriad
    Member
    Posted 2 years ago #

    Maybe there's someone else looking for the same thing so here's how I've done it:

    <div class="pages-thumbs" <?php if (false == strpos($_SERVER['REQUEST_URI'], 'page')) {

    if ($wp_query->current_post < 1) echo 'id="the-first-post"';

    } ?>>

    </div>

    If the URL contains "page" in the URL, this doesn't apply that id to the div but if it doesn't, the containing div gets the id=the-first-post".

  3. alchymyth
    Forum Moderator
    Posted 2 years ago #

    is_paged() http://codex.wordpress.org/Function_Reference/is_paged

    if ($wp_query->current_post < 1 && !is_paged())

Topic Closed

This topic has been closed to new replies.

About this Topic