2012-03-19 68 views
0

我使用WP出版物存檔插件WP_Query標題鏈接無法顯示

我想列出出版附着到自定義模板,所以我寫了下面的代碼。

第一個只顯示標題。但我想要的是直接鏈接到發佈文件

所以在類別ID 13我需要近5文件直接下載鏈接列表

<?php 

// The Query 
$the_query = new WP_Query('cat=13&post_type=publication&numberposts=5'); 

// The Loop 
    while ($the_query->have_posts()) : $the_query->the_post(); 
    echo '<li>'; 
    the_title(); 
    echo '</li>'; 
    endwhile; 

// Reset Post Data 
wp_reset_postdata(); 


?> 

下面一個沒有顯示鏈接,請告訴我錯了嗎?

  <?php 

      // The Query 
      $the_query = new WP_Query('cat=13&post_type=publication&numberposts=5'); 

      // The Loop 

       while ($the_query->have_posts()) : $the_query->the_post(); 
        echo '<a href="<?php the_permalink() ?>"><?php the_title(); ?></a>';   
       endwhile; 

      // Reset Post Data 
      wp_reset_postdata(); 

      ?> 

回答

0

試試這個您的循環中:

echo '<a href="' . the_permalink() . '">' . the_title() . '</a>'; 
+0

鏈接都OK和標題是確定的,但在我的頁面顯示如下 沒有鏈接到標題 http://project.xxx.com/wp-content/plugins/wp-publication-archive/includes/openfile.php?file=http|project.xxx .COM /可溼性粉劑內容/上傳/ 2012/03/tor_proce ss_monitoring.pdf這是一個演示文件(下載出版物) – user1132928 2012-03-19 23:07:44

1

你的問題是在這裏:

while ($the_query->have_posts()) : $the_query->the_post(); 
    echo '<a href="<?php the_permalink() ?>"><?php the_title(); ?></a>';   
endwhile; 

你已經在一個PHP代碼塊,打開一個又一個。你應該做這樣的

<?php $the_query = new WP_Query(...); ?> 
<?php while ($the_query->have_posts()) : $the_query->the_post(); ?> 
    <a href="<?php the_permalink() ?>"><?php the_title(); ?></a>   
<?php endwhile; ?> 
<?php wp_reset_postdata(); ?> 
+0

謝謝!!!謝謝!!!謝謝!! – user1132928 2012-03-19 23:15:45

0

東西也許看起來很蠢,但work..try這個.. :)

//主循環

while (have_posts()) : the_post(); <br /> 
    echo `'<div class="box_news">';` <br /> 
    the_post_thumbnail(array(60,60), array ('class' => 'post_home_img')); <br /> 
    echo `'<h3 class="post_home_title">';` <br /> 
    echo `'<a href="';` <br/> 
    the_permalink(); <br/> 
    echo `'">';` <br/> 
    the_title(); <br/> 
    echo `'</a>';` <br/> 
    echo `'</h3>';` <br/> 
    the_excerpt(); <br/> 
    echo `'</div>';` <br/> 
endwhile;