Advertisement
uzielweb

Wordpress - retrieving all top images from a post

May 24th, 2016
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <meta http-equiv="content-type" content="text/html; charset=utf-8">
  5. <meta name="generator" content="PSPad editor, www.pspad.com">
  6. <title></title>
  7. <!-- Latest compiled and minified CSS -->
  8. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
  9.  
  10. <!-- Optional theme -->
  11. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
  12.  
  13. <!-- Latest compiled and minified JavaScript -->
  14. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
  15. <style>
  16. body *{
  17. font-size:14px;
  18. color: #333;
  19.  
  20. }
  21. table td {
  22. padding: 10px;
  23. }
  24. thead td, thead td * {
  25. background: #818181 none repeat scroll 0 0;
  26. color: #fff !important;
  27. font-weight: bold;
  28. padding: 10px;
  29. text-align: left !important;
  30. text-transform: uppercase;
  31. }
  32. body > .container {
  33. padding-top: 40px;
  34. background-color: white;
  35.  
  36. }
  37.  
  38. /*
  39. * Responsive stypes
  40. */
  41. @media (max-width: 980px) {
  42.  
  43. body > .container {
  44. padding-top: 0px;
  45. }
  46. .navbar-fixed-top {
  47. margin-bottom: 0;
  48. }
  49.  
  50. } /* END: @media (max-width: 980px) */
  51. </style>
  52. </head>
  53. <body>
  54.  
  55. <div class="container">
  56. <div class="col-md-12 jumbotron">
  57. <p>
  58. <?php
  59. $servername = "localhost";
  60. $username = "xxx";
  61. $password = "xxx";
  62. $dbname = "xxxx";
  63.  
  64.  
  65.  
  66.  
  67. // Create connection
  68.  
  69. $conn = new mysqli($servername, $username, $password, $dbname);
  70. mysqli_set_charset($conn, "utf8");
  71. // Check connection
  72. if ($conn->connect_error) {
  73. die("Connection failed: " . $conn->connect_error);
  74. }
  75. // output data of each row
  76. foreach ($conn->query('SELECT ID, post_date, post_title, post_type, post_name, guid FROM nyk3_posts WHERE post_type = "post" ORDER BY ID ASC') as $row){
  77. echo "<b>ID: </b>".$row["ID"]." - <b>TÍTULO: </b><a data-toggle='lightbox' rel='modal' href='".$row["guid"]."' target='_blank'>". $row["post_title"]."</a> - <b>DATA: </b>". $row["post_date"];
  78. echo "<br>";
  79.  
  80. foreach ($conn->query('SELECT ID, post_parent,guid FROM nyk3_posts WHERE post_type = "attachment"') as $row2){
  81.  
  82. if ($row2["post_parent"] == $row["ID"]) {
  83. foreach ($conn->query('SELECT post_id,meta_value, meta_key FROM nyk3_postmeta WHERE meta_key = "_thumbnail_id"') as $row3)
  84. if ($row3["meta_value"] == $row2["ID"]) {
  85. foreach ($conn->query('SELECT post_id,meta_value, meta_key FROM nyk3_postmeta WHERE meta_key = "_wp_attached_file"') as $row4){
  86. if ($row4["post_id"] == $row3["meta_value"]) {
  87. echo "<a data-toggle='lightbox' rel='modal' href='wp-content/uploads/".$row4["meta_value"]."' target='_blank'>".$row4["meta_value"]."</a><br><br>";
  88. }
  89.  
  90. }
  91. }
  92. }
  93. }
  94.  
  95.  
  96. }
  97.  
  98.  
  99. $conn->close();
  100. ?>
  101. </p>
  102. </div></div>
  103.  
  104. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  105. </body>
  106. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement