Title: conditional inside loop
Last modified: August 18, 2016

---

# conditional inside loop

 *  [machinetype](https://wordpress.org/support/users/machinetype/)
 * (@machinetype)
 * [19 years, 4 months ago](https://wordpress.org/support/topic/conditional-inside-loop-1/)
 * Hello,
 * The code I have below displays the last 20 posts made. I was wondering if its
   possible to isolate a specific post with a conditional to NOT have a link and
   only display the title.
 * `<?php
    $lastposts = get_posts('numberposts=20'); foreach($lastposts as $post):
   setup_postdata($post); ?> <li> <a href="<?php the_permalink(); ?>" id="post-<?
   php the_ID(); ?>"><?php the_title(); ?></a> </li> <?php endforeach; ?>
 * ex. say i have 3 links
    link1 link2 link3 <- not clickable
 * Say im on the link3 post. Id want link1 and link2 to have the permalinks, but
   i dont want link 3 to be clickable.
 * Any help would be appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Doodlebee](https://wordpress.org/support/users/doodlebee/)
 * (@doodlebee)
 * [19 years, 4 months ago](https://wordpress.org/support/topic/conditional-inside-loop-1/#post-511711)
 * Out of curiosity – why would you want to do this? There may be a better solution
   for whatever it is you’re trying to do.
 *  Thread Starter [machinetype](https://wordpress.org/support/users/machinetype/)
 * (@machinetype)
 * [19 years, 4 months ago](https://wordpress.org/support/topic/conditional-inside-loop-1/#post-511722)
 * Well I have links on the sidebar that are links to posts. The posts are assigned
   a class based on which page they are on. Like if your on page 3, the link for
   page 3 has a white bg applied to it.
 * If theres another way to make accomplish this, let me know.
 *  [Doodlebee](https://wordpress.org/support/users/doodlebee/)
 * (@doodlebee)
 * [19 years, 4 months ago](https://wordpress.org/support/topic/conditional-inside-loop-1/#post-511732)
 * [Sure there is.](http://codex.wordpress.org/Dynamic_Menu_Highlighting) There’s
   a “Fold Page List” plugin that you can customize to use as well.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘conditional inside loop’ is closed to new replies.

## Tags

 * [conditional](https://wordpress.org/support/topic-tag/conditional/)
 * [inside](https://wordpress.org/support/topic-tag/inside/)
 * [loop](https://wordpress.org/support/topic-tag/loop/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [Doodlebee](https://wordpress.org/support/users/doodlebee/)
 * Last activity: [19 years, 4 months ago](https://wordpress.org/support/topic/conditional-inside-loop-1/#post-511732)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
