Forums

query_id help (5 posts)

  1. djames04
    Member
    Posted 2 years ago #

    I am at a loss.

    thedynamicmediagroup.com

    I'm needing to get the ID number that is in my loop query for a given post. Maybe I will need to figure out how to recode my slider, but what I think I need is something like this..

    <ul id="projects">
    <!--[BEGIN FEATURED PROJECTS LOOP]-->
    <?php
    $featured = new WP_Query();
    $featured->query('showposts=4');
    while($featured->have_posts()) : $featured->the_post();

    $wp_query->in_the_loop = true;
    $featured_ID = $post->ID;
    ?>

    <li class="project" id="project-1">

    Where project-1 would be project-[the query ID] 1-4. The reason being is because this is how my slider works.. after x-amount of time it slides to my next numerical post... however, as is it isn't changing where the arrow points to.

    This is the only thing that I think is keeping my slider from working properly.. but.. I don't know much about how they work either...

    Could someone help me out.

    Thanks.

  2. alchymyth
    The Sweeper
    Posted 2 years ago #

    i think you already have the ID here:
    $featured_ID = $post->ID;

    you could try and output it at the respective place:

    <li class="project" id="project-<?php echo $featured_ID; ?>">

  3. djames04
    Member
    Posted 2 years ago #

    Let's say that the Post number is 193.. would that place 193 in that spot or would it place the Query number in that spot? As in, the 4th queried post id? Make sense?

  4. alchymyth
    The Sweeper
    Posted 2 years ago #

    i would think it will leave the post number, ie 193 in the place.

    it was not too clear from your first question if you want the post id or a number between 1 and 4?

  5. alchymyth
    The Sweeper
    Posted 2 years ago #

    if you want the 1 to 4, you could try to introduce a counter variable:

    <ul id="projects">
    <!--[BEGIN FEATURED PROJECTS LOOP]-->
    <?php $counter = 0;
    $featured = new WP_Query();
    $featured->query('showposts=4');
    while($featured->have_posts()) : $featured->the_post();
    $counter++;
    $wp_query->in_the_loop = true;
    $featured_ID = $post->ID;
    ?>
    
    <li class="project" id="project-<?php echo $counter; ?>">

Topic Closed

This topic has been closed to new replies.

About this Topic