Different style for each post in wordpess!

Wordpress is most popular CMS for making website. All kinds of wordpress related discussion goes here!
Post Reply
User avatar
shojol80
Global Moderator
Global Moderator
Posts: 9
Joined: Thu Sep 26, 2013 9:39 pm

Different style for each post in wordpess!

Post by shojol80 » Thu Nov 14, 2013 12:50 am

Today i will share a custom wordpress query with you.if you want to show last ten post from a category but you want to give different style for each post you can use this query


Code: Select allexpand
<?php
$category= "YOUR CAT NAME";
query_posts('post_type=post&cat='.$category.'&post_status=publish&orderby=ID&posts_per_page=2&paged='. get_query_var('paged')); ?>
<?php $c =0;
if (have_posts()) : while (have_posts()) : the_post();
$c++;?>

<?php if($c == 1 ) :?>
<h1><?php the_title(); ?></h1>
<?php elseif($c == 2) :?>
<h6><?php the_title(); ?></h6>

<?php else:?>

<?php endif;?>

<?php endwhile; ?>

<?php endif; ?>
<?php wp_reset_query(); ?>
[/size]
]:)



User avatar
Administrator
Site Owner
Site Owner
Posts: 203
Joined: Mon Sep 23, 2013 2:02 am

Re: Different style for each post in wordpess!

Post by Administrator » Thu Nov 14, 2013 5:10 am

$c =0;

is it your own variable?

User avatar
shojol80
Global Moderator
Global Moderator
Posts: 9
Joined: Thu Sep 26, 2013 9:39 pm

Re: Different style for each post in wordpess!

Post by shojol80 » Sat Nov 16, 2013 10:41 am

yes,,$C=0 mean we are startting from first post,,,,,

User avatar
timidshare424
Registered Member
Registered Member
Posts: 1
Joined: Sat Sep 24, 2016 8:42 pm

Re: Different style for each post in wordpess!

Post by timidshare424 » Tue Sep 27, 2016 3:49 pm

I came here just to thank you. Because I was searching everywhere for this method. Thanks :)

User avatar
Administrator
Site Owner
Site Owner
Posts: 203
Joined: Mon Sep 23, 2013 2:02 am

Re: Different style for each post in wordpess!

Post by Administrator » Thu Nov 03, 2016 11:27 am

timidshare424 wrote:I came here just to thank you. Because I was searching everywhere for this method. Thanks :)
You are welcome here

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest