riner — 2012-04-03T09:17:13-04:00 — #1
Hi guys, i´ve knoledge of html/css/+-js and im just knew to wordpress&php stuff.
Im building my own template and im having so much trouble finding the information i need...and i hope someone could give me a light, heres the deal:
I wanna make a section of a page that filter the 5 most recent posts with categories of my wish.
Example: in this section it will show the most 5 recent posts within the categories "food" and "restaurant". If theres none show a message and if theres more then 5 show a button like "show more" or something like that...
I know there´s a PHP code for that and im searching, made some tries but i cant get it to work...
Thank you already.
mike_fro — 2012-04-03T09:43:07-04:00 — #2
Assuming you are using Wordpress here is some code that should do the trick. Replace category ID's with the ones you would like to be displayed though:
<?php $recent = new WP_Query("cat=1&showposts=10"); while($recent->have_posts()) : $recent->the_post();?>
<li><a href="<?php the_permalink() ?>" rel="bookmark">
<?php the_title(); ?>
<?php endwhile; ?>
riner — 2012-04-03T10:24:26-04:00 — #3
Thanks for the fast reply @mike.fro but i want something a little more complicated, as my english fails i illustrated to show more accurately the idea!
Here it is:
Basically it wil show:
1: The Mother Category (if ti has one).
2: The Category.
3: The Categorie description (it is already defined when the categorie was created).
4: The posts that has both categories.
=X little complicated...
mike_fro — 2012-04-03T10:46:27-04:00 — #4
Something like this:
while(have_posts()) : the_post();
<li><h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>
<ul><li><?php the_excerpt(); ?></li>
<?php endwhile; ?>
This may take some tweaking on your end. But it should be enough to get you started. Let me know if I provided the wrong solution... again, hehe =P
riner — 2012-04-03T13:38:43-04:00 — #5
Thank you very much, i made it!!! Of course the project has several pages, it will need a lot of time but the codes are working!
mike_fro — 2012-04-03T13:53:21-04:00 — #6
Yes, not a problem. Glad I could help. Like I said, it will take some customizing on your end to make it look however you'd like but the core is there for you to work with.
riner — 2012-04-05T10:09:55-04:00 — #7
Yeah i made it, its working all good, hehe.
mittineague — 2014-09-22T03:27:55-04:00 — #8
This topic is now archived. It is frozen and cannot be changed in any way.