2014-01-30 2 views
0
<?php 
$the_query = new WP_Query(array( 
    'post_type' => 'needs', 
    'orderby' => 'date', 
    'category_name' => 'volunteers', //name of category by slug 
    'order' => 'DESC', 
    'posts_per_page' => '5')); // how many posts to show 

    // Put into the loop 
    while ($the_query->have_posts()) : 
    $the_query->the_post(); 
    echo '<tr><td>' . get_the_date() . '</td>'; 
    echo '<td>' . get_the_title() . '</a></td></tr>'; 

    endwhile; 



    // Restore original Post Data if needed 
    wp_reset_postdata(); ?> 

나는이 코드를 사용하여 자원 봉사자 범주에서 필요성의 제목과 날짜를 정확하게 표시합니다. 게시물 자체에 링크 할 제목이 필요하지만이 코드로 퍼머 링크를 사용할 수 없습니다. 아이디어가 있으십니까?제목 자체를 클릭 할 수있게하십시오. (Wordpress)

답변

1

에 만약 get_the_title()이 작동하지 왜 아무 이유도 정말 당신을 위해 일하고있다 없다 :

<?php 
$the_query = new WP_Query(array( 
    'post_type' => 'needs', 
    'orderby' => 'date', 
    'category_name' => 'volunteers', //name of category by slug 
    'order' => 'DESC', 
    'posts_per_page' => '5')); // how many posts to show 

    // Put into the loop 
    while ($the_query->have_posts()) : 
    $the_query->the_post(); 
    echo '<tr><td>' . get_the_date() . '</td>'; 
    echo '<td><a href="' . get_permalink($post->ID) . '">' . get_the_title() . '</a></td></tr>'; 

    endwhile; 



    // Restore original Post Data if needed 
    wp_reset_postdata(); ?> 

이 그것을 밖으로 시도가 !

+0

이것은 맞습니다. 또 다른 방법은 다음과 같습니다. echo '' . get_the_title() . ''; 귀하와 귀하의 차이점은 무엇입니까? 둘 다 작동합니다. – 4ndy

+0

다행 당신을 위해 일했다! get_the_ID()는 단순히 $ post 변수에서 ID를 가져 오는 함수이므로 차이가 없습니다. $ post-> ID는 동일한 ID를 얻는보다 적절하고 직접적인 방법이며 더 자주 볼 수 있습니다. – jrobson153

1

변화

echo '<td>' . get_the_title() . '</a></td></tr>'; 

echo '<td><a href="'. get_permalink($post->ID) . '">' . get_the_title() . '</a></td></tr>'; 
+0

이 방법은 현재 내가 현재 사용하고있는 페이지에 실제로 링크되어 있습니다. 게시물 자체에는 없습니다. – 4ndy

+0

나중에 실현했습니다 .. updated – juz

관련 문제