WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am struggling with the php structure. How do I need to rewrite the code to get the links to the titles and thumbnails of the custom posts?

<ul class="thumbnails">
    <?php $pfportfolio = new WP_Query( 'post_type=portfolio', 'posts_per_page=-1' );?>
    <?php while ( $pfportfolio->have_posts() ) : $pfportfolio->the_post();?>

        echo '<li class="span4" data-id="post-'.get_the_ID().'" data-type="'.$terms_as_text = strip_tags( get_the_term_list( $post->ID, 'location', '', ' ', '' ) ).'">';
        **echo '<span class="projekte-title">';
        echo '</span>';
        echo '<div class="thumbnail">';
        echo '</div>';**
        echo '</li>';?>

    <?php endwhile; ?>

   <?php  wp_reset_postdata(); ?>

I assume I need to integrate somehow

<a href="<?php echo get_permalink(); ?>"></a>

but unfortunately I just dont understand how :(. Thanks so much for any help!

share|improve this question

Something like this should solve your problem...

<?php $pfportfolio = new WP_Query( array('post_type'=>'portfolio', 'posts_per_page'=>-1) ); ?>
<?php if ( $pfportfolio->have_posts() ): ?>
<ul class="thumbnails">
    <?php while ( $pfportfolio->have_posts() ) : $pfportfolio->the_post(); ?>
    <li class="span4" data-id="post-<?php echo esc_attr(get_the_ID()); ?>" data-type="<?php echo esc_attr(strip_tags( get_the_term_list( $post->ID, 'location', '', ' ', '' ) ) ); ?>">
        <a href="<?php the_permalink(); ?>"><span class="projekte-title"><?php the_title(); ?></span></a>
        <div class="thumbnail"><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('home-feat'); ?></a></div>
    <?php endwhile; ?>
    <?php wp_reset_postdata(); ?>
<?php endif; ?>
share|improve this answer

You can use $post->ID to get current post id ( get_permalink($post->ID) ) and also can use function the_permalink() to show url

share|improve this answer
Well, inside the loop you can use the_permalink tag. – Krzysiek Dróżdż Jul 30 '13 at 18:34
Sorry i forgot to mention "inside the loop" – Vikram Jul 30 '13 at 18:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.