Here is how to get WordPress Genesis home page grid with CSS column without any plugin or even front-page or home template. Very easy to create. Genesis and other paid themes can not compete with the recent changes for schema markups. At the time of publication of this article, you can check official StudioPress blog is failing to pass Google Microformat Testing Tool, but we are passing. Most wants a semi static home page and people writes most difficult ways to create grid in responsive design. Our basic target is to – decrease the number of queries and PHP snippet. PHP is not as good as Python or even Perl.
Table of Contents |
WordPress Genesis Home Page Grid With CSS Column : Plan The Things
Basically all needs some boxes or call to action stuffs on homepage plus the latest posts. What will be your layout is your matter, but you can conditionally add plain HTML stuffs on front-page using Genesis Simple Hooks Plugin in this way in the “genesis_before_content_sidebar_wrap” Hook box (enable Execute PHP on this hook
by tick mark) :
---
The above gist is loading as async defer script in non-blocking way. We are not even loading the CSS on other webpages like posts. Very easy. Plain HTML and CSS. Now we need to remove the fucking navigation on homepage only :
When W3TC will cache it, there will no stress on the database or extra PHP query. This is a bit advanced usage of what we did with drop caps on Posts only. If you have lot of images on homepage as slider, use Base64 data URI. Google dislike that navigation on serious website – they becomes repeat if you consider the categories. By this time, you got a better looking homepage.
But we promised you – WordPress Genesis Home Page Grid With CSS Column. If you are browsing this webpage via desktop, then pull the ear of your browser window to look it like a mobile and navigate below this article where related articles are present. The thing is Yet Another Related Post but we added micro data with custom template. You will see – on desktop there are three columns. When you’ll make it smaller – it will become 2 columns. Excellent responsive idea for home page recent posts. Grid is nothing but a visual matter.
WordPress Genesis Home Page Grid With CSS Column
You definitely have some horizontal separators between the recent posts. Like “—–“. If you add column like “|”, it becomes like “H”. But when you’ll go for mobile, it should become like “[ ]”. The columns should break to normal condition. We will add only a CSS :
So the final code would be :
No body has told you to not use PHP within the HTML divs. You can easily add. If you want to position the post images on homepage over the title, you need to reposition. Adding a small snippet on child theme’s functions.php
will work fine :
1 2 3 4 5 6 7 | function tcw_reposition_home_image() { if ('is_archive') { remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 ); add_action( 'genesis_entry_header', 'genesis_do_post_image', 8 ); } } add_action( 'genesis_before_content', 'tcw_reposition_home_image' ); |
We used tcw_reposition_home
, you can change it with the name you like. Now, from the Genesis Theme settings page, activate “Include the Featured Image” by tick mark and select a horizontally bigger image. We do not use it as it increases the HTTTP requests.
Indeed, you can show recent posts from one category using Doug Edgington’s this snippet on child theme’s functions.php
file :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | function dee_display_recent_posts() { $args = array( 'post_type' => 'post', 'posts_per_page'=> 5, 'cat'=> 4, ); $dee_recent_posts = new WP_Query( $args ); if( $dee_recent_posts->have_posts() ): $dee_output = '<ul>'; while ( $dee_recent_posts->have_posts() ) : $dee_recent_posts->the_post(); $dee_output .= '<li><a href="' . get_permalink() . '" title="' . get_the_title() . '">' . get_the_title() . '</a></li>'; endwhile; $dee_output .= '</ul>'; endif; return $dee_output; wp_reset_postdata(); } add_shortcode( 'recent-posts', 'dee_display_recent_posts' ); |
[recent-posts]
is the short code here. What more a template offers? Less, it adds more burden on the server.
Extra : Centering in Responsive With CSS
Now, look at our sidebars Ads and again pull the ear of your browser window to make it like a mobile. You’ll see that our Ads are remaining in the center. We wrapped the divs with :
1 2 3 4 5 6 7 8 9 10 11 12 13 | <div class="google-doubleclick"> </div> <style> .google-doubleclick { background-color: #EEEEEE; background-repeat: no-repeat; max-width:300px; max-height:100%; margin:0 auto; text-align: center; } </style> |
max-width:300px
is fixed for this case as the container is bigger than 300px in width when responsive, but generally max-width:100%;
usually works.
Have we asked money from you? Simple work, if you read here and there; you could also write it. We do not ask for Nginx PHP5 FPM Fix, we asked money for this small thing?
You want design? There are hundreds of design for free on Github. Get the CSS and HTML and modify. Simple.
How Home Page Grid With CSS Column Works and Why It is Not For Category Pages
We have removed the pagination. All the posts became under the div class named content
. If you add this for Category, the numbering unfortunately will get fully messed up. The only way is to add a new div class after the itemprop maincontentOfpage i.e. at the beginning of the posts loop. But ending the div before the navigation ois very difficult. It probably need a template modification. Again the problem of closed source becomes apparent. After huge trial and error normally a solution for category page will be discovered.
As the post titles will never have exactly the same number of words, there will be small problem in cometic appearance, it will not be exact grid but a more realistic stuff – like Newspaper Columns.
Tagged With home page cloumn , CSS grid