Anton
asked 9 years ago

I would like to show the last posts’ excerpts of certain categories using php. Something like this:

<?php $posts = get_posts ("category=66&orderby=date&numberposts=3"); ?> 
<?php if ($posts) : ?>
<?php foreach ($posts as $post) : setup_postdata ($post); ?>
 
       <div class="name">
            <a href="<?php the_permalink() ?>"><?php the_excerpt(); ?></a>
        </div>
     
<?php endforeach; ?>
<?php endif; ?>

But as a result I get 3 excerpts of one post from a different (not id=66) category. Could you help me? Thanks in advance.

2 Answers
Allen
answered 9 years ago

hi anton 😀 , in my opinion , you shouldn’t query like that 🙂 , you can try this 😀

$args = array (
'posts_per_page' => '3',
'category' => '66',
'orderby' => 'post_date',
),
$posts = get_pots( $args );

If your want to research more about this , you can find something useful here  😀
http://codex.wordpress.org/Template_Tags/get_posts
there are many args for you to query 😀 
 

Anton
replied 9 years ago

Could you upload the full code, please? I have no skills in programming, I'm just a Google-user 🙂

PS There is an error in redirection to the profiles. For example your final path looks like http://www.designwall.com/bloghttp:/www.designwall.com/profile/nobita/ => "Not Found."

Anton
answered 9 years ago

Ok, I’ve found the right code with your help 🙂

<?php
global $post;
$args = array( 'posts_per_page' => 3,  'category' => 66, 'orderby' => 'post_date' );
$posts = get_posts( $args );
foreach( $posts as $post ) :    setup_postdata($post); ?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?><?php the_excerpt(); ?></a>
<?php endforeach; ?>

But I still require your help here, if it wouldn’t be too much trouble: 😀 http://www.designwall.com/question/the-3rd-level-of-the-menu

nobita
replied 9 years ago

Well , sorry for reply a bit late 😀 , it's really good when you can resolve the problem by your self 😀 i appreciate that 😀 To show the sub-subcategories , all you need to do is use the wp_nav_menu();
Find in header.php , line 105-117
The $param ( short for parameters ) is like the criteria for the function query out that Menu 😀 if you don't use $param in the functions , all categories , sub-categories … sub sub-categories will show , but it'll not have their style , css , and you need to custom style your self again 😀
Normally all the sub subcategories show there but they use css to hide them with the param : ( 'menu_class' => 'nav', ) to insert class wrap all the menu and style them in css file :D. And sorry , sr that i'm not good att css 🙁

Powered by DW Question & Answer Pro