Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. <?php
  2. add_shortcode( 'prefix_alphabetic_posts', 'prefix_alphabetic_posts' );
  3. function prefix_alphabetic_posts() {
  4. ob_start();
  5. ?>
  6. <style type="text/css">
  7. #alphabetical-posts .letters li {
  8. display: inline-block;
  9. margin: 0;
  10. }
  11. #alphabetical-posts .letters a {
  12. text-decoration: none;
  13. font-size: 16px;
  14. background: #ffffff;
  15. height: 2em;
  16. display: inline-block;
  17. width: 2em;
  18. line-height: 2em;
  19. color: #2196F3;
  20. margin: 0;
  21. }
  22. #alphabetical-posts .letters {
  23. text-align: center;
  24. display: inline-flex;
  25. }
  26. #alphabetical-posts .letters-wrap {
  27. text-align: center;
  28. }
  29. #alphabetical-posts .letters a:hover {
  30. background: #2196F3;
  31. color: #fff;
  32. }
  33. #alphabetical-posts .posts {
  34. margin-top: 4em;
  35. max-width: 900px;
  36. margin: 0 auto;
  37. }
  38. #alphabetical-posts .posts .item {
  39. margin-bottom: 4em;
  40. }
  41. #alphabetical-posts .posts .item a {
  42. text-decoration: none;
  43. font-size: 14px;
  44. }
  45. #alphabetical-posts .posts .list > div {
  46. background: #fff;
  47. padding: 15px 15px;
  48. border-bottom: 1px solid #f2f2f2;
  49. }
  50. #alphabetical-posts .list h3 {
  51. margin: 0;
  52. }
  53. #alphabetical-posts .list .content {
  54. margin-top: 5px;
  55. }
  56. </style>
  57. <?php
  58. $result = prefix_get_posts_group_by_alphabet();
  59. if( $result ) { ?>
  60. <div id="alphabetical-posts">
  61. <?php $letters = array_keys($result); ?>
  62. <?php if( $letters ) { ?>
  63. <div class="letters-wrap">
  64. <ul class="letters">
  65. <?php foreach( $letters as $key => $letter ) { ?>
  66. <li><a href="#goto-letter-<?php echo $letter; ?>"><?php echo $letter; ?></a></li>
  67. <?php } ?>
  68. </ul>
  69. </div>
  70. <?php } ?>
  71. <div class="posts">
  72. <?php foreach( $result as $letter => $posts ) { ?>
  73. <div id="goto-letter-<?php echo $letter; ?>" class="item">
  74. <h3><?php echo $letter; ?></h3>
  75. <div class="list">
  76. <?php foreach( $posts as $key => $post ) { ?>
  77. <div>
  78. <h3><a href="#"><?php echo $post['title']; ?></a></h3>
  79. <div class="content">
  80. <?php echo wp_trim_words( get_the_excerpt( $post['ID'] ), 20 ); ?>
  81. </div>
  82. </div>
  83. <?php } ?>
  84. </div>
  85. </div>
  86. <?php } ?>
  87. </div>
  88. </div>
  89. <?php }
  90. return ob_get_clean();
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement