2015-10-27 124 views
1

我想顯示某個類別的帖子到顯示縮略圖的頁面,然後鏈接到完整的帖子。這將成爲案例研究部分。僅顯示來自一個類別的wordpress帖子

我有鏈接顯示並帶我通過,但它顯示所有帖子,而不是像我想要的特定類別。

任何想法?我不熟悉PHP和只使用WordPress

剛纔所說

我的代碼:

<?php // PAGE LINK/TITLE 

if (is_page()) { 
    $cat=get_cat_ID($post->post_title); //use page title to get a category ID 
    $posts = get_posts ("cat=$cat&showposts=10"); 
    if ($posts) { 
    foreach ($posts as $post): 
     setup_postdata($post); 

if (has_post_thumbnail()) { // PULLS IN IMAGE check if the post has a Post Thumbnail assigned to it. 
    the_post_thumbnail(); 
} 

?> 

<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> 

<?php //PULLS IN EXCERPT 
$my_excerpt = get_the_excerpt(); 
if ('' != $my_excerpt) { 
    // Some string manipulation performed 
} 
echo $my_excerpt; // Outputs the processed value to the page 

?> 

<?php endforeach; 
    } 
} 
?> 
+0

哪個模板要覆蓋? –

+0

裸體worpdress主題 – 5kud

+0

我問的是哪個模板(page.php,index.php,archive.php,content.php等),而不是詢問主題? –

回答

0

沒有特定類別集中,只有職位的量要顯示,在這種情況下爲10.

<?php // PAGE LINK/TITLE 


if (is_page()) { 
    $cat=get_cat_ID($post->post_title); //use page title to get a category ID 

    $posts = get_posts ("category_name=service&posts_per_page=10"); //CHANGE CODE AND ADD THIS LINE*************************** 

    if ($posts) { 
    foreach ($posts as $post): 
     setup_postdata($post); 

        if (has_post_thumbnail()) { // PULLS IN IMAGE check if the post has a Post Thumbnail assigned to it. 
    the_post_thumbnail(); 
} 


    ?> 

This設置特定的類別和職位(使用類別塞拉它)

CATEGORY_NAME數=服務& posts_per_page = 10

0

<?php 
 
$catPost = get_posts(get_cat_ID("NameOfTheCategory")); //change this 
 
    foreach ($catPost as $post) : setup_postdata($post); ?> 
 
     <div> 
 
      <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> 
 
      <p><?php the_content(); ?></p> 
 
     </div> 
 
<?php endforeach;?>

相關問題