Skip to main content
added div and css classes
Source Link
Michael
  • 8.4k
  • 3
  • 29
  • 31

you haven't stated where the category id will come from, nor how you want to style the category title, and if the post titles are supposed to be linked to the single post; therefore just the basic structure:

<?php 
$cat_id = 137; 
    echo '<div class="category-title">'.get_category($cat_id)->name;>name.'</div>;
    $cat_posts = get_posts(array('category__in' => array($cat_id), 'posts_per_page' =>5));
    if($cat_posts) {
        echo '<ul>';'<ul class="category-posts">';
        foreach($cat_posts as $cat_post) {
            echo '<li>''<li class="category-post">'.get_the_title($cat_post->ID).'</li>';
        }
        echo '</ul>';
    }
?>

you haven't stated where the category id will come from, nor how you want to style the category title, and if the post titles are supposed to be linked to the single post; therefore just the basic structure:

<?php 
$cat_id = 137; 
    echo get_category($cat_id)->name;
    $cat_posts = get_posts(array('category__in' => array($cat_id), 'posts_per_page' =>5));
    if($cat_posts) {
        echo '<ul>';
        foreach($cat_posts as $cat_post) {
            echo '<li>'.get_the_title($cat_post->ID).'</li>';
        }
        echo '</ul>';
    }
?>

you haven't stated where the category id will come from, nor how you want to style the category title, and if the post titles are supposed to be linked to the single post; therefore just the basic structure:

<?php 
$cat_id = 137; 
    echo '<div class="category-title">'.get_category($cat_id)->name.'</div>;
    $cat_posts = get_posts(array('category__in' => array($cat_id), 'posts_per_page' =>5));
    if($cat_posts) {
        echo '<ul class="category-posts">';
        foreach($cat_posts as $cat_post) {
            echo '<li class="category-post">'.get_the_title($cat_post->ID).'</li>';
        }
        echo '</ul>';
    }
?>
Source Link
Michael
  • 8.4k
  • 3
  • 29
  • 31

you haven't stated where the category id will come from, nor how you want to style the category title, and if the post titles are supposed to be linked to the single post; therefore just the basic structure:

<?php 
$cat_id = 137; 
    echo get_category($cat_id)->name;
    $cat_posts = get_posts(array('category__in' => array($cat_id), 'posts_per_page' =>5));
    if($cat_posts) {
        echo '<ul>';
        foreach($cat_posts as $cat_post) {
            echo '<li>'.get_the_title($cat_post->ID).'</li>';
        }
        echo '</ul>';
    }
?>