dustyhawk
asked 6 years ago

based on the suggestion here  ” http://cmspioneer.com/designwall/question/first-4-post-to-be-at-double-and-the-rest-single/
i would like to know where in the files should i edit so that every new post made will be “double” on the front page.
 

dustyhawk
replied 6 years ago

tried this but it broke my wallpress.

5 Answers
well wisher
answered 6 years ago

Hi here is your solution:

Just need to insert content  into home.php and edit home.php like this

<div id=”content” class=”masonry”>
<?php $i=0; ?>
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php $i++ ?>
<?php
if ($i==4): $cls=’class=” ‘. implode(‘ ‘,get_post_class()).’ grid-double “‘;
else : $cls=’class=” ‘. implode(‘ ‘,get_post_class()).’ “‘;
endif;
?>
<div id=”item-<?php the_ID(); ?>” <?php echo $cls ?> >
<div class=”item-inner”>
<?php if( has_post_format(‘gallery’) ) : ?>

Change the $i==whatever you want(i have set it to 4 for your answer) Source: http://designwall.com/question/how-to-make-the-first-post-on-page-double-sized-grid-double-without-using-custom-fields/

well wisher
answered 6 years ago

can you drop a screen shot or explain what kinda problem did it created >
And i suppose you would have copied everything supplied above into the home.php while what you just need to do is as follows:
Add this

<?php $i=0; ?>

just after

<div id=”content” class=”masonry”>

and this

<?php $i++ ?><?php
if ($i==4): $cls=’class=” ‘. implode(‘ ‘,get_post_class()).’ grid-double “‘;
else : $cls=’class=” ‘. implode(‘ ‘,get_post_class()).’ “‘;
endif;
?>
<div id=”item-<?php the_ID(); ?>” <?php echo $cls ?> >
<div class=”item-inner”>
<?php if( has_post_format(‘gallery’) ) : ?>

just after

<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>

well wisher
answered 6 years ago

You can see they have implemented to show there first post as double grid by default in there site they have mentioned in the question i embeded above. The logic how its working is as follows: define a variable $i and assign its default value as 0 this line does that for you <?php $i=0;?> Then the last two lines of the code i mentioned in my updated answer above checks if there are more posts in the database and if yes then bring them up on  front end of my site from the database until there are no more posts left to show and while each post is loaded the line <?php $i++?> keeps incrementing the value of variable $i by 1
And the middle section logic is turning the post no. 3 as double grid by default.

<?php if($i==4)…grid-double…?>

thing is saying if its post no.3 just it to grid double and his line mentioned below is saying if its not post no. 3never mind just do normal work and brig out the post as normal with single grid or whatever it has been assigned

else : $cls=’class=” ‘. implode(‘ ‘,get_post_class()).’ “‘;
endif;

   

well wisher
answered 6 years ago

Now if that works for and you want to change the first 4 questions by default to grid double what you can just try is this replace this line


<?php $i++ ?><?php
if ($i==4): $cls=’class=” ‘. implode(‘ ‘,get_post_class()).’ grid-double “‘;
else : $cls=’class=” ‘. implode(‘ ‘,get_post_class()).’ “‘;
endif;
?>

like this


<?php $i++ ?><?php
if ($i==0 || $i==1 || $i==2 || $i==3): $cls=’class=” ‘. implode(‘ ‘,get_post_class()).’ grid-double “‘;
else : $cls=’class=” ‘. implode(‘ ‘,get_post_class()).’ “‘;
endif;
?>

dustyhawk
replied 6 years ago

this is what i meant about it broke – http://www.uploadhouse.com/viewfile.php?id=19106444

well wisher
replied 6 years ago

that screen shot says your site got blank after you did the modifications,did you read and follow the instructions as i gave above or did you just copied everything into the file i would recommend not to do modifications if its not working for you but at the same time i will once again say that it worked for the person whose answer i embeded as the source over here!!!
The site they have implemented it on is valvetimes.com.
In that case Only designwall team can only help you and m sorry that it dint worked for you.

dustyhawk
replied 6 years ago

reread everything. did the same and still broke. hopefully the designwall team are reading this and can help me

Wilfred
answered 6 years ago

Hi dustyhawk
To resolve this issue please follow my instruction here:
1. Open file home.php in your site / wp-content / themes / your theme / home.php.
2. Replace following code – line 19

 <?php while ( have_posts() ) : the_post(); ?>

with

 <?php global $i; $i = 0; while ( have_posts() ) : the_post(); ?>

3. Replace following code – line 23

 <?php endwhile; ?>

with

 <?php $i++; endwhile; ?>

4. Open file content.php in your site / wp-content / themes / your theme / content.php.

5.Replace following code – line 1

 <div id="item-<?php the_ID(); ?>" <?php post_class(); ?> >

with: 

 <?php 
$class = '';
if (is_home()) {
global $i;
if ($i < 3) {
$class="grid-double";
} else {
$class="grid-single";
}
}
?>
<div id="item-<?php the_ID(); ?>" <?php post_class($class); ?> >

Hope this helps !

dustyhawk
replied 6 years ago

hey @wilfred .

what do i need to do if i want to have it for category and archive view as well ?

Powered by DW Question & Answer Pro