2012-03-19 106 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;