2017-11-01 19 views
0

플러그인없이 WordPress의 특정 카테고리에서 모든 게시물 URL을 나열 할 수있는 방법이 있습니까? 저는 PHP에 익숙하지 않습니다. 그러나 어떤 방법으로,이 모든 카테고리 게시물 URL (예 : 카테고리 "blog"를 호출 할 수있는 방법)을 호출하는 페이지 템플리트를 사용할 수 있다고 생각했습니다.목록 WordPress 특정 카테고리의 게시물 URL

답변

1

검토 WP_Query 및 WordPress 루프. 이런 식으로 뭔가 내가 제대로 (PHP 태그의 랩을) 문의를 이해하고있어 경우에 작동한다고 :

$the_query = new WP_Query(array('category_name' => 'blog')); 

if ($the_query->have_posts()) { 
echo '<ul>'; 
while ($the_query->have_posts()) { 
    $the_query->the_post(); 
    echo '<li>' . get_permalink() . '</li>'; 
} 
echo '</ul>'; 
/* Restore original Post Data */ 
wp_reset_postdata(); 
} else { 
// no posts found 
} 
1

당신은 get_posts (https://codex.wordpress.org/Template_Tags/get_posts)를 사용할 수 있습니다.

원하는 게시물의 배열을 반환하는 WP_Query의 슬림 다운 버전을 고려하십시오.

$categoryPosts = get_posts(array(
    // Note: The category parameter needs to be the ID of the category, and not the category name. 
    'category' => 1, 
    // Note: The category_name parameter needs to be a string, in this case, the category name. 
    'category_name' => 'Category Name', 
)); 

그런 다음 당신은 글을 반복 할 수 있습니다

foreach($categoryPosts as $categoryPost) { 
    // Your logic 
} 

$categoryPost은 (사용자 정의 필드를 가지면 더 필드),이 필드는 분명히 채워집니다 기본적으로 다음이 포함됩니다 만, 이것은 무엇이다 배열로 사용할 수 있습니다 :

WP_Post Object 
(
    [ID] => 
    [post_author] => 
    [post_date] => 
    [post_date_gmt] => 
    [post_content] => 
    [post_title] => 
    [post_excerpt] => 
    [post_status] => 
    [comment_status] => 
    [ping_status] => 
    [post_password] => 
    [post_name] => 
    [to_ping] => 
    [pinged] => 
    [post_modified] => 
    [post_modified_gmt] => 
    [post_content_filtered] => 
    [post_parent] => 
    [guid] => 
    [menu_order] => 
    [post_type] => 
    [post_mime_type] => 
    [comment_count] => 
    [filter] => 
)