wordpress - WP: How to get just one post, from one category and show it -



wordpress - WP: How to get just one post, from one category and show it -

hello guys! have code, shows 1 post each category need show 1 post, , need set "name" of category i'm trying this:

<?php $cat_args = array( 'orderby' => 'name', 'order' => 'asc', 'child_of' => 0 ); $categories = get_categories($cat_args); foreach($categories $category) { echo '<dl>'; echo '<dt> <a href="' . get_category_link( $category->name ) . '" title="' . sprintf( __( "view posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a></dt>'; $post_args = array( 'numberposts' => 1, 'category' => $category->term_id ); $posts = get_posts($post_args); foreach($posts $post) { ?> <dd><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></dd> <div class="entry"> <?php the_content(); ?> </div> <?php } echo '<dd class="view-all"> <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "view posts in %s" ), $category->name ) . '" ' . '>view posts in ' . $category->name.'</a></dd>'; echo '</dl>'; } ?>

i searched codex , have not found way categories name, can help me??

what you're looking get_cat_id.

change $post_args this:

$post_args = array( 'posts_per_page' => 1, 'cat' => get_cat_id( 'my category name' ) );

let me know how goes. :)

wordpress post category

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -