Advertisement
abilicom

Mutiple recent posts

Dec 3rd, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. <?php
  2. define('WP_USE_THEMES', false);
  3. ?>
  4. <?php
  5. require('./editorials/wp-load.php');
  6. $content1 = array();
  7. ?>
  8. #start editorials loop
  9. <ul>
  10.  
  11. <?php $the_query = new WP_Query( 'posts_per_page=10' ); ?>
  12.  
  13. <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
  14.  
  15. <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
  16.  
  17. <li><?php the_excerpt(__('(more…)')); ?></li>
  18.  
  19. <?php
  20. $content1[]=array(get_the_date('Ymd'). '%%' . get_the_id(). '%%' . get_the_title(). '%%' . get_the_permalink(). '%%' . get_the_author(). '%%' . get_the_post_thumbnail(). '%%'. wp_first_paragraph_excerpt($content));
  21. //print_r ($content1);
  22. ?>
  23. <?php
  24. endwhile;
  25. wp_reset_postdata();
  26. ?>
  27. </ul>
  28. #end editorials loop
  29. <?php
  30. require('./news/wp-load.php');
  31. wp_reset_query();
  32. $content2 = array();
  33. ?>
  34. #start news loop
  35. <ul>
  36. <?php $the_query = new WP_Query( 'posts_per_page=10' ); ?>
  37. <?php wp_reset_postdata();
  38. wp_reset_query();
  39. ?>
  40. <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
  41.  
  42. <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
  43.  
  44. <li><?php the_excerpt(__('(more…)')); ?></li>
  45. <?php
  46. $content2[]=array(get_the_date('Ymd'). '%%' . get_the_id(). '%%' . get_the_title(). '%%' . get_the_permalink(). '%%' . get_the_author(). '%%' . get_the_post_thumbnail(). '%%'. wp_first_paragraph_excerpt($content));
  47. //print_r ($content2);
  48. ?>
  49. <?php
  50. endwhile;
  51. ?>
  52. #all done
  53. <?php
  54.  
  55. function wp_first_paragraph_excerpt($content) {
  56. // Get the post content
  57. $content = get_the_content();
  58. $content = apply_filters( 'the_content', strip_shortcodes( $content ) );
  59. // Remove all tags, except paragraphs
  60. $excerpt = strip_tags( $content, '<p></p>' );
  61. // Remove empty paragraph tags
  62. $excerpt = force_balance_tags( $excerpt );
  63. $excerpt = preg_replace( '#<p>\s*+(<br\s*/*>)?\s*</p>#i', '', $excerpt );
  64. $excerpt = preg_replace( '~\s?<p>(\s|&nbsp;)+</p>\s?~', '', $excerpt );
  65. // Get the first paragraph
  66. $excerpt = substr( $excerpt, 0, strpos( $excerpt, '</p>' ) + 4 );
  67. // Remove remaining paragraph tags
  68. $excerpt = strip_tags( $excerpt );
  69. return $excerpt;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement