Advertisement
Ronburgundyy

Wordpress Masonry Page Template Explanation

May 19th, 2013
4,266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. // An explanation on using:
  2. // http://wp.tutsplus.com/tutorials/theme-development/using-jquery-masonry-for-pinterest-like-posting/
  3. /************************** This goes in your functions.php **************************/
  4. //script enque
  5. function mason_script() {
  6. wp_enqueue_script( 'jquery-masonry' );
  7. }
  8. add_action( 'wp_enqueue_scripts', 'mason_script' );
  9.  
  10. /****** Create a new php file and name it whatever you want, this will act as a page template. *********************/
  11. /************************** Put this inside of that new php file **************************/
  12.  
  13. <?php
  14. /**
  15. * Template Name: Masonry Blog
  16. *
  17. * Blog Template
  18. *
  19. */
  20. ?>
  21. <?php include_once( 'header.php' ); ?>
  22. <!-- Start the Loop. -->
  23. <div id="container2">
  24. <?php
  25. $temp = $wp_query;
  26. $wp_query= null;
  27. $wp_query = new WP_Query();
  28. $wp_query->query('posts_per_page=100'.'&paged='.$paged);
  29. while ($wp_query->have_posts()) : $wp_query->the_post();
  30. ?>
  31. <div class="brick">
  32. <div class="brick_header">
  33. <a href="<?php the_permalink() ?>" rel="bookmark" title="Click to view: <?php the_title_attribute(); ?>">
  34. <?php the_title(); ?></a>
  35. </div>
  36. <div class="brick_featured_image">
  37. <?php if ( has_post_thumbnail() ) {
  38. $size=75;
  39. ?>
  40. <a href="<?php the_permalink() ?>" rel="bookmark" title="Click to view: <?php the_title_attribute(); ?>">
  41. <?php the_post_thumbnail( $size ); } ?>
  42. </a>
  43. </div>
  44. <?php the_excerpt(); ?>
  45. <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>" class="read_more_link">Read More</a>
  46. </div>
  47. <?php endwhile;?>
  48. <?php $wp_query = null; $wp_query = $temp;?>
  49. <!-- stop The Loop. -->
  50. </div><!-- container -->
  51. <?php get_footer(); ?>
  52.  
  53. /*********************** Put this in your styles.css file or whateve stylesheet you use **************************/
  54.  
  55. /* masonry brick layout */
  56. #container2 {
  57. width: 100%; /* width of the entire container for the wall */
  58. margin-bottom: 10px;
  59. }
  60.  
  61. .brick {
  62. width: 20%; /* width of each brick less the padding inbetween */
  63. padding: 0px 10px 15px 10px;
  64. background-color: #383838;
  65. margin-top: 5px;
  66. }
  67.  
  68. .brick_header{
  69. border-bottom: solid 1px #1d1d1d;
  70. padding-bottom: 10px;
  71. padding-top: 10px;
  72. }
  73. .brick_header a{
  74. color: #ffff00;
  75. }
  76. .brick_header a:hover{
  77. color: white;
  78. }
  79. .brick_featured_image{
  80. width: 100%;
  81. margin-top: 10px;
  82. }
  83. .brick_featured_image img{
  84. width: 100%;
  85. height: auto;
  86. }
  87.  
  88. /*********************** Put this somewhere in your footer.php file **************************/
  89. /*********************** maybe just before <?php wp_footer(); ?> **************************/
  90.  
  91. <script>
  92. jQuery( document ).ready( function( $ ) {
  93. $( '#container2' ).masonry( { columnWidth: 220 } );
  94. } );
  95. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement