HTML / CSS creando varios loops en varias columnas


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <!-- el CSS que se tendría que añadir a style.css al final de todo (un ejemplo, se puede hacer con px) -->
  2.  
  3. .columna{
  4. width:30%;
  5. float:left;
  6. margin-right:3%
  7. }
  8.  
  9. .columna h5 a{
  10. color:#D90819
  11. }
  12.  
  13. <!-- el HTML y PHP en index.php, etc-->
  14.  
  15. <div class="columna">
  16.  
  17. <?php
  18. $category_id = get_cat_ID( 'Categorí­a 1' );
  19. $category_link = get_category_link( $category_id );
  20. ?>
  21. <h5><a href="<?php echo $category_link; ?>" title="Categorí­a 1">Categorí­a 1</a></h5>
  22.  
  23. <?php
  24. $posts = get_posts('category_name=noticias&numberposts=3');
  25. foreach($posts as $post):
  26. setup_postdata($post);
  27. ?>
  28.  
  29. <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
  30. <?php the_excerpt(); ?>
  31.  
  32. <?php $posttags = get_the_tags($post->ID); if ($posttags) {
  33. foreach($posttags as $tag) {
  34. echo '<a href="';
  35. echo get_tag_link($tag);
  36. echo '">';
  37. echo $tag->name . ' ';
  38. echo '</a>';
  39. }
  40. }
  41. ?>
  42. <?php endforeach; ?>
  43.  
  44. </div>
  45.  
  46. <div class="columna">
  47.  
  48. <?php
  49. $category_id = get_cat_ID( 'Categorí­a 2' );
  50. $category_link = get_category_link( $category_id );
  51. ?>
  52. <h5><a href="<?php echo $category_link; ?>" title="Categorí­a 2">Categorí­a 2</a></h5>
  53.  
  54. <?php
  55. $posts = get_posts('category_name=cine&numberposts=3');
  56. foreach($posts as $post):
  57. setup_postdata($post);
  58. ?>
  59.  
  60. <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
  61. <?php the_excerpt(); ?>
  62.  
  63. <?php $posttags = get_the_tags($post->ID); if ($posttags) {
  64. foreach($posttags as $tag) {
  65. echo '<a href="';
  66. echo get_tag_link($tag);
  67. echo '">';
  68. echo $tag->name . ' ';
  69. echo '</a>';
  70. }
  71. }
  72. ?>
  73. <?php endforeach; ?>
  74.  
  75. </div>
  76.  
  77. <div class="columna">
  78.  
  79. <?php
  80. $category_id = get_cat_ID( 'Categorí­a 3' );
  81. $category_link = get_category_link( $category_id );
  82. ?>
  83. <h5><a href="<?php echo $category_link; ?>" title="Categorí­a 3">Categorí­a 3</a></h5>
  84.  
  85. <?php
  86. $posts = get_posts('category_name=musica&numberposts=3');
  87. foreach($posts as $post):
  88. setup_postdata($post);
  89. ?>
  90.  
  91. <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
  92. <?php the_excerpt(); ?>
  93.  
  94. <?php $posttags = get_the_tags($post->ID); if ($posttags) {
  95. foreach($posttags as $tag) {
  96. echo '<a href="';
  97. echo get_tag_link($tag);
  98. echo '">';
  99. echo $tag->name . ' ';
  100. echo '</a>';
  101. }
  102. }
  103. ?>
  104. <?php endforeach; ?>
  105.  
  106. </div>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.