Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

2 Answers 2

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" –  Vicky 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.