Advertisement
terorama

WP / tests4

Mar 29th, 2013
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 20.68 KB | None | 0 0
  1. <?php
  2.  
  3. //-------------------------------------------------
  4. define('WP_USE_THEMES', false);
  5. require('../wp-load.php');
  6. header('Content-type: text/html; charset=utf-8');
  7. //-------------------------------------------------
  8.  
  9. ?>
  10.  
  11. <style type="text/css">
  12.    li {
  13.       border-top: solid 3px #f80;
  14.    }
  15. </style>
  16.  
  17. <?php
  18.  
  19. //cats_tree();
  20.  
  21. /*get_cats4();
  22. get_posts4();*/
  23.  
  24. //post_stats();
  25. //user_stats();
  26. //comm_stats();
  27.  
  28. tests6();
  29. //get_posts4();
  30.  
  31. //------------------------------------------------
  32. function info() {
  33.    echo 'stylesheet_dir='.get_stylesheet_directory().'<br/>';
  34.    echo 'stylesheet_uri='.get_stylesheet_directory_uri().'<br/>';
  35.    echo 'template_dir='.get_template_directory().'<br/>';
  36.    echo 'template_uri='.get_template_directory_uri().'<br/>';
  37.  
  38.    echo str_repeat('-',50).'<br/>';
  39.  
  40.    echo 'name='.get_bloginfo('name').'<br/>';
  41.    echo 'description='.get_bloginfo('description').'<br/>';
  42.    echo 'wpurl='.get_bloginfo('wpurl').'<br/>';
  43.    echo 'admin_email='.get_bloginfo('admin_email').'<br/>';
  44.    echo 'charset='.get_bloginfo('charset').'<br/>';
  45.    echo 'version='.get_bloginfo('version').'<br/>';
  46.    echo 'html_type='.get_bloginfo('html_type').'<br/>';
  47.    echo 'language='.get_bloginfo('language').'<br/>';
  48.    echo 'stylesheet_url='.get_bloginfo('stylesheet_url').'<br/>';
  49.    echo 'stylesheet_dir='.get_bloginfo('stylesheet_directory').'<br/>';
  50.    echo 'template_url='.get_bloginfo('template_url').'<br/>';
  51.    echo 'template_dir='.get_bloginfo('template_directory').'<br/>';
  52.  
  53.    echo 'pingback_url='.get_bloginfo('pingback_url').'<br/>';
  54.    echo 'atom_url='.get_bloginfo('atom_url').'<br/>';
  55.    echo 'rdf_url='.get_bloginfo('rdf_url').'<br/>';
  56.    echo 'rss_url='.get_bloginfo('rss_url').'<br/>';
  57.    echo 'rss2_url='.get_bloginfo('rss2_url').'<br/>';
  58.    echo 'comments_atom_url='.get_bloginfo('comments_atom_url').'<br/>';
  59.    echo 'comments_rss2_url='.get_bloginfo('comments_rss2_url').'<br/>';
  60.    
  61.  
  62.    
  63. }
  64. //------------------------------------------------
  65. function atts5() {
  66.  
  67.    $args = array('post_type'=>'post', 'post_status'=>'publish');
  68.  
  69.    $que = new WP_Query($args);
  70.  
  71.    while ($que->have_posts()) {
  72.       $que->the_post();
  73.       echo '<br/><br/>'; the_title(); echo '<br/>';
  74.  
  75.       if (has_post_thumbnail(get_the_id())) {
  76.          draw_att(get_the_id());
  77.       }
  78.    }
  79.    
  80. }
  81.    
  82. //----------------------------------------
  83. function draw_att($postID)
  84. {
  85.    $args = array(
  86.         'numberposts' => 1,
  87.         'order' => 'ASC',
  88.         'post_mime_type' => 'image',
  89.         'post_parent' => $postID,
  90.         'post_status' => null,
  91.         'post_type' => 'attachment',
  92.     );
  93.  
  94.     $attachments = get_children( $args );
  95.  
  96.     if ( $attachments ) {
  97.         foreach ( $attachments as $attachment ) {
  98.  
  99.             $image_attributes = wp_get_attachment_image_src(
  100.  
  101.                        $attachment->ID, 'thumbnail' )  ?
  102.  
  103.                         wp_get_attachment_image_src( $attachment->ID, 'thumbnail' ) :
  104.                         wp_get_attachment_image_src( $attachment->ID, 'full' );
  105.  
  106.                         echo  'img_attrs=<pre>'.print_r($image_attributes,true).'</pre><br/>';
  107.             echo  wp_get_attachment_thumb_url( $attachment->ID ).'<br/>';
  108.         }
  109.     }
  110. }
  111.  
  112. //------------------------------------------------
  113. function atts4() {
  114.  
  115.    $images =& get_children( 'post_type=attachment&post_mime_type=image' );
  116.  
  117.    if ( empty($images) ) {
  118.     // no attachments here
  119.    } else {
  120.         echo '<ul>';
  121.     foreach ( $images as $attachment_id => $attachment ) {
  122.  
  123.         //echo wp_get_attachment_image( $attachment_id, 'full' );
  124.  
  125.                 echo '<li>'.wp_get_attachment_link( $attachment_id,
  126.               'thumbnail', true, false, get_permalink($attachment_id)).'</li>';
  127.     }
  128.         echo '</ul>';
  129.   }
  130.  
  131.  
  132. }
  133.  
  134.  
  135. //-------------------------------------------------
  136. function tests6() {
  137.    
  138. /*--------------------------------
  139.  
  140. $query = new WP_Query( 'author=123' );
  141. $query = new WP_Query( 'author_name=rami' );
  142. $query = new WP_Query( 'author=2,6,17,38' );
  143. $query = new WP_Query( 'author=-12' );
  144. $query = new WP_Query( 'cat=4' );
  145. $query = new WP_Query( 'category_name=staff' );
  146. $query = new WP_Query( 'category__in=4' );
  147. $query = new WP_Query( 'cat=2,6,17,38' );
  148. $query = new WP_Query( 'category_name=staff,news' );
  149. $query = new WP_Query( 'cat=-12,-34,-56' );
  150. $query = new WP_Query( array( 'category__and' => array( 2, 6 ) ) );
  151. $query = new WP_Query( array( 'category__in' => array( 2, 6 ) ) );
  152. $query = new WP_Query( array( 'category__not_in' => array( 2, 6 ) ) );
  153. $query = new WP_Query( 'tag=cooking' );
  154. $query = new WP_Query( 'tag_id=13' );
  155. $query = new WP_Query( 'tag=bread,baking' );
  156. $query = new WP_Query( 'tag=bread+baking+recipe' );
  157. $query = new WP_Query( array( 'tag__and' => array( 37, 47 ) ) );
  158. $query = new WP_Query( array( 'tag__in' => array( 37, 47 ) ) );
  159. $query = new WP_Query( array( 'tag__not_in' => array( 37, 47 ) ) );
  160. ------------------------------
  161. $args = array(
  162.     'post_type' => 'post',
  163.     'people' => 'bob'
  164. );
  165. $query = new WP_Query( $args );
  166. ------------------------------
  167. $args = array(
  168.     'post_type' => 'post',
  169.     'tax_query' => array(
  170.         array(
  171.             'taxonomy' => 'people',
  172.             'field' => 'slug',
  173.             'terms' => 'bob'
  174.         )
  175.     )
  176. );
  177. $query = new WP_Query( $args );
  178. ------------------------------
  179. $args = array(
  180.     'post_type' => 'post',
  181.     'people' => 'bob',
  182.     'language' => 'english'
  183. );
  184. $query = new WP_Query( $args );
  185. ------------------------------
  186. $args = array(
  187.     'post_type' => 'post',
  188.     'tax_query' => array(
  189.         'relation' => 'AND',
  190.         array(
  191.             'taxonomy' => 'movie_genre',
  192.             'field' => 'slug',
  193.             'terms' => array( 'action', 'comedy' )
  194.         ),
  195.         array(
  196.             'taxonomy' => 'actor',
  197.             'field' => 'id',
  198.             'terms' => array( 103, 115, 206 ),
  199.             'operator' => 'NOT IN'
  200.         )
  201.     )
  202. );
  203. $query = new WP_Query( $args );
  204. ------------------------------
  205. $args = array(
  206.     'post_type' => 'post',
  207.     'tax_query' => array(
  208.         'relation' => 'OR',
  209.         array(
  210.             'taxonomy' => 'category',
  211.             'field' => 'slug',
  212.             'terms' => array( 'quotes' )
  213.         ),
  214.         array(
  215.             'taxonomy' => 'post_format',
  216.             'field' => 'slug',
  217.             'terms' => array( 'post-format-quote' )
  218.         )
  219.     )
  220. );
  221. $query = new WP_Query( $args );
  222. ------------------------------
  223. $query = new WP_Query( 's=keyword' );
  224. ------------------------------
  225. $query = new WP_Query( 'p=7' );
  226. $query = new WP_Query( 'page_id=7' );
  227. $query = new WP_Query( 'name=about-my-life' );
  228. $query = new WP_Query( 'pagename=contact' );
  229. $query = new WP_Query( 'pagename=contact_us/canada' );
  230. $query = new WP_Query( 'post_parent=93' );
  231. $query = new WP_Query( 'post_parent=0' );
  232. $query = new WP_Query( array( 'post_type' => 'page', 'post__in' => array( 2, 5, 12, 14, 20 ) ) );
  233. $query = new WP_Query( array( 'post_type' => 'post', 'post__not_in' => array( 2, 5, 12, 14, 20 ) ) );
  234. $query = new WP_Query( 'post_type=page' );
  235. $query = new WP_Query( 'post_type=any' );
  236. $query = new WP_Query( array( 'post_type' => array( 'post', 'page', 'movie', 'book' ) ) );
  237. $query = new WP_Query( 'post_status=draft' );
  238. $query = new WP_Query( array( 'post_status' => array( 'pending', 'draft', 'future' ) ) );
  239. $query = new WP_Query( array( 'post_status' => 'any', 'post_type' => 'attachment' ) );
  240. $query = new WP_Query( 'posts_per_page=3' );
  241. $query = new WP_Query( 'posts_per_page=-1' );
  242. $query = new WP_Query( 'nopaging=true' );
  243. $query = new WP_Query( 'offset=3' ) );
  244. $query = new WP_Query( array( 'posts_per_page' => 5, 'offset' => 3 ) );
  245. $query = new WP_Query( 'paged=6' );
  246. $query = new WP_Query( array( 'paged' => get_query_var( 'paged' ) ) );
  247.  
  248. -------------------------------------
  249. $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  250. $query = new WP_Query( array( 'paged' => $paged ) );
  251. -------------------------------------
  252. $paged = (get_query_var('page')) ? get_query_var('page') : 1;
  253. $query = new WP_Query( array( 'paged' => $paged ) );
  254. -------------------------------------
  255. $query = new WP_Query( array ( 'orderby' => 'title', 'order' => 'DESC' ) );
  256. $query = new WP_Query( array ( 'orderby' => 'rand', 'posts_per_page' => '1' ) );
  257. $query = new WP_Query( array( 'orderby' => 'comment_count' ) );
  258. $query = new WP_Query( array ( 'post_type' => 'product', 'orderby' => 'meta_value', 'meta_key' => 'price' ) );
  259. $query = new WP_Query( array( 'post_type' => 'page', 'orderby' => 'title menu_order', 'order' => 'ASC' ) );
  260. -------------------------------------
  261. $args = array(
  262.    'post_type' => 'my_custom_post_type',
  263.    'meta_key' => 'age',
  264.    'orderby' => 'meta_value_num',
  265.    'order' => 'ASC',
  266.    'meta_query' => array(
  267.        array(
  268.            'key' => 'age',
  269.            'value' => array(3, 4),
  270.            'compare' => 'IN',
  271.        )
  272.    )
  273.  );
  274.  $query = new WP_Query($args);
  275. -------------------------------------
  276.  
  277. $sticky = get_option( 'sticky_posts' );
  278. $query = new WP_Query( 'p=' . $sticky[0] );
  279.  
  280. -------------------------------------
  281. $args = array(
  282.     'posts_per_page' => 1,
  283.     'post__in'  => get_option( 'sticky_posts' ),
  284.     'ignore_sticky_posts' => 1
  285. );
  286. $query = new WP_Query( $args );
  287.  
  288. -------------------------------------
  289. $sticky = get_option( 'sticky_posts' );
  290. $args = array(
  291.     'posts_per_page' => 1,
  292.     'post__in'  => $sticky,
  293.     'ignore_sticky_posts' => 1
  294. );
  295. $query = new WP_Query( $args );
  296. if ( $sticky[0] ) {
  297.     // insert here your stuff...
  298. }
  299. -------------------------------------
  300. $query = new WP_Query( array( 'post__not_in' => get_option( 'sticky_posts' ) ) );
  301. $query = new WP_Query( array( 'ignore_sticky_posts' => 1, 'posts_per_page' => 3, 'cat' => 6 );
  302. -------------------------------------
  303.  
  304. $paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
  305. $sticky = get_option( 'sticky_posts' );
  306. $args = array(
  307.     'cat' => 3,
  308.     'ignore_sticky_posts' => 1,
  309.     'post__not_in' => $sticky,
  310.     'paged' => $paged
  311. );
  312. $query = new WP_Query( $args );
  313. -------------------------------------
  314.  
  315. $today = getdate();
  316. $query = new WP_Query( 'year=' . $today["year"] . '&monthnum=' . $today["mon"] . '&day=' . $today["mday"] );
  317. -------------------------------------
  318.  
  319. $week = date('W');
  320. $year = date('Y');
  321. $query = new WP_Query( 'year=' . $year . '&w=' . $week );
  322.  
  323. -------------------------------------
  324.  
  325. $query = new WP_Query( 'monthnum=12&day=20' );
  326.  
  327. -------------------------------------
  328. // Create a new filtering function that will add our where clause to the query
  329. function filter_where( $where = '' ) {
  330.     // posts for March 1 to March 15, 2010
  331.     $where .= " AND post_date >= '2010-03-01' AND post_date < '2010-03-16'";
  332.     return $where;
  333. }
  334.  
  335. add_filter( 'posts_where', 'filter_where' );
  336. $query = new WP_Query( $query_string );
  337. remove_filter( 'posts_where', 'filter_where' );
  338.  
  339. -------------------------------------
  340. // Create a new filtering function that will add our where clause to the query
  341. function filter_where( $where = '' ) {
  342.     // posts in the last 30 days
  343.     $where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'";
  344.     return $where;
  345. }
  346.  
  347. add_filter( 'posts_where', 'filter_where' );
  348. $query = new WP_Query( $query_string );
  349. remove_filter( 'posts_where', 'filter_where' );
  350.  
  351. -------------------------------------
  352. // Create a new filtering function that will add our where clause to the query
  353. function filter_where( $where = '' ) {
  354.     // posts  30 to 60 days old
  355.     $where .= " AND post_date >= '" . date('Y-m-d', strtotime('-60 days')) . "'" . " AND post_date <= '" . date('Y-m-d', strtotime('-30 days')) . "'";
  356.     return $where;
  357. }
  358.  
  359. add_filter( 'posts_where', 'filter_where' );
  360. $query = new WP_Query( $query_string );
  361. remove_filter( 'posts_where', 'filter_where' );
  362.  
  363. -------------------------------------
  364. $query = new WP_Query( 'meta_key=color' );
  365. $query = new WP_Query( 'meta_value=blue' );
  366. $query = new WP_Query( 'meta_value=blue&post_type=page' );
  367. $query = new WP_Query( array( 'meta_key' => 'color', 'meta_value' => 'blue' ) );
  368. $query = new WP_Query( array( 'meta_key' => 'color', 'meta_value' => 'blue', 'meta_compare' => '!=' ) );
  369. -------------------------------------
  370. $query = new WP_Query( array( 'meta_key' => 'price', 'meta_value' => '22', 'meta_compare' => '<=', 'post_type' => 'product' ) );
  371. -------------------------------------
  372. $query = new WP_Query( array ( 'meta_value' => '_wp_zero_value' ) );
  373. -------------------------------------
  374. $args = array(
  375.     'post_type' => 'product',
  376.     'meta_query' => array(
  377.         array(
  378.             'key' => 'color',
  379.             'value' => 'blue',
  380.             'compare' => 'NOT LIKE'
  381.         )
  382.     )
  383. );
  384. $query = new WP_Query( $args );
  385. -------------------------------------
  386. $args = array(
  387.     'post_type' => 'product',
  388.     'meta_query' => array(
  389.         array(
  390.             'key' => 'color',
  391.             'value' => 'blue',
  392.             'compare' => 'NOT LIKE'
  393.         ),
  394.         array(
  395.             'key' => 'price',
  396.             'value' => array( 20, 100 ),
  397.             'type' => 'numeric',
  398.             'compare' => 'BETWEEN'
  399.         )
  400.     )
  401. );
  402. $query = new WP_Query( $args );
  403. -------------------------------------
  404. $args = array(
  405.     'post_type' => 'product',
  406.     'meta_query' => array(
  407.         'relation' => 'OR',
  408.         array(
  409.             'key' => 'color',
  410.             'value' => 'blue',
  411.             'compare' => 'NOT LIKE'
  412.         ),
  413.         array(
  414.             'key' => 'price',
  415.             'value' => array( 20, 100 ),
  416.             'type' => 'numeric',
  417.             'compare' => 'BETWEEN'
  418.         )
  419.     )
  420. );
  421. $query = new WP_Query( $args );
  422.  
  423. -------------------------------------
  424. $query = new WP_Query( array( 'post_status' => array( 'publish', 'private' ), 'perm' => 'readable' ) );
  425.  
  426. $query = new WP_Query( array( 'posts_per_page' => 50, 'cache_results' => false ) );
  427. $query = new WP_Query( array( 'posts_per_page' => 50, 'update_post_meta_cache' => false ) );
  428. $query = new WP_Query( array( 'posts_per_page' => 50, 'update_post_term_cache' => false ) );
  429.  
  430.  
  431.  
  432. ----------------------------------*/
  433.    $args = array('post_type'=>'post');
  434.  
  435.    $query = new WP_Query($args);
  436.  
  437.    while ($query->have_posts()) {
  438.  
  439.       $query->the_post();
  440.    }
  441. }
  442. //-------------------------------------------------
  443. function tests5() {
  444.  
  445.  $args =  array( 'post_type'=>'post', 'order'=>'DESC', 'post_per_page'=>3);
  446.  $query = new WP_Query($args);
  447.  
  448.  echo '<ul>';
  449.  
  450.  while ($query->have_posts()) {
  451.    
  452.  
  453.    echo '<li>';
  454.  
  455.    $query->the_post();
  456.    echo 'id='; the_id(); echo '<br/>';
  457.    echo 'permalink='; the_permalink(); echo '<br/>';
  458.    echo 'title='; the_title(); echo '<br/>';
  459.    echo 'date='; the_date(); echo '<br/>';
  460.    echo 'time='; the_time(); echo '<br/>';
  461.    echo 'category='; the_category(); echo '<br/>';
  462.    echo 'tags='; the_tags(); echo '<br/>';
  463.    echo 'author='; the_author(); echo '<br/>';
  464.    echo 'author_link='; the_author_link(); echo '<br/>';
  465.    echo 'meta='; the_meta(); echo '<br/>';
  466.    echo 'shortlink='; the_shortlink(); echo '<br/>';
  467.    echo 'terms='; the_terms(get_the_id(),'category'); echo '<br/>';
  468.    echo 'taxonomies='; the_taxonomies(); echo '<br/>';
  469.  
  470.    
  471.    echo '</li>';
  472.  }
  473.  
  474.  echo '</ul>';
  475.  
  476.    
  477. }
  478.  
  479. //-------------------------------------------------
  480.  
  481. function tests4() {
  482.  
  483.    $posts = get_posts('numberposts=1&offset=0&orderby=title');
  484.  
  485.    echo '<ul>';
  486.    foreach ($posts as $post) {
  487.       echo '<li>';
  488.          //echo '<pre>'.print_r($post,true).'</pre>';
  489.  
  490.          echo
  491.          'id='.       $post->ID.'<br/>'.
  492.          'author='.   $post->post_author.'<br/>'.
  493.          'date='.     $post->post_date.'<br/>'.
  494.          'date_gmt='. $post->post_date_gmt.'<br/>'.
  495.          'content='. '<br/>'.
  496.          'title='. $post->post_title.'<br/>'.
  497.          'excerpt='. htmlentities($post->post_excerpt).'<br/>'.
  498.          'status='. $post->post_status.'<br/>'.
  499.          'comment_status='. $post->comment_status.'<br/>'.
  500.          'ping_status='.$post->ping_status.'<br/>'.
  501.          'name='.$post->post_name.'<br/>'.
  502.          'modified='.$post->post_modified.'<br/>'.
  503.          'modified_gmt='.$post->post_modified_gmt.'<br/>'.
  504.          'parent='.$post->post_parent.'<br/>'.
  505.          'guid='.$post->guid.'<br/>'.
  506.          'type='.$post->post_type.'<br/>'.
  507.          'mime_type='.$post->post_mime_type.'<br/>'.
  508.          'comment_count='.$post->comment_count.'<br/>';
  509.  
  510.          echo 'permalink='.get_permalink($post->ID).'<br/>';
  511.  
  512.       echo '</li>';
  513.    }
  514.    echo '</ul>';
  515. }
  516.  
  517.  
  518. //-------------------------------------------------
  519. function comm_stats() {
  520. $args = array(
  521.  
  522.         'post_id' => $id,
  523.         'order'=>'DESC'
  524.    
  525. );
  526. $comments = get_comments($args);
  527.  
  528. echo '<ul>';
  529.  
  530. foreach($comments as $c) :
  531.  
  532.   echo '<li>';
  533.  
  534.      echo 'comment_id='.$c->comment_ID.'<br/>'.
  535.       'comment_post_id='.$c->comment_post_ID.'<br/>'.
  536.        'comment_author='.$c->comment_author.'<br/>'.
  537.        'comment_author_email='.$c->comment_author_email.'<br/>'.
  538.         'comment_author_url='.$c->comment_author_url.'<br/>'.
  539.        'comment_author_ip='.$c->comment_author_IP.'<br/>'.
  540.        'comment_date='.$c->comment_date.'<br/>'.
  541.        'comment_date_gmt='.$c->comment_date_gmt.'<br/>'.
  542.        'comment_content='.$c->comment_content.'<br/>'.
  543.        'comment_karma='.$c->comment_karma.'<br/>'.
  544.        'comment_approved='.$c->comment_approved.'<br/>'.
  545.        'comment_agent='.$c->comment_agent.'<br/>'.
  546.        'comment_type='.$c->comment_type.'<br/>'.
  547.        'comment_parent='.$c->comment_parent.'<br/>'.
  548.        'user_id='.$c->user_id.'<br/>';
  549.        
  550.  
  551.  
  552.     echo '</li>';
  553. endforeach;
  554.  
  555. echo '</ul>';
  556. }
  557. //-------------------------------------------------
  558. function user_stats() {
  559.  
  560.     $blogusers = get_users('orderby=nicename');
  561.  
  562.     foreach ($blogusers as $user) {
  563.         echo '<li>' .
  564.         $user->user_login.'<br/>'.
  565.         $user->user_pass.'<br/>'.
  566.         $user->user_nicename.'<br/>'.
  567.        
  568.         $user->user_email .'<br/>' .
  569.         $user->user_url.'<br/>'.
  570.         $user->user_registered.'<br/>'.
  571.         $user->user_status.'<br/>'.
  572.         $user->display_name.
  573.           '</li>';
  574.     }
  575. }
  576. //-------------------------------------------------
  577. function post_stats() {
  578.  
  579.    $args = array( 'post_type'=>'post', 'order'=>'ASC',
  580.                   'nopaging'=>true,  );
  581.  
  582.    $query = new WP_Query( $args);
  583.  
  584.    echo '<ul>';
  585.    while ($query->have_posts()) {
  586.  
  587.        $query->the_post();
  588.        echo '<li><table><tr><td>';
  589.  
  590.        the_shortlink('Link');
  591.  
  592.         echo '</td><td>'.
  593.           '<a href="'.get_permalink().'" target="_blank">'.get_the_title().'</a></td>'.
  594.         '<td>'.implode('<br/>',get_post_class()).'</td>'.
  595.         '<td>comments='.get_comments_number().'</td>'.
  596.         '</tr></table></li>';
  597.  
  598.    }
  599.    echo '</ul>';
  600. }
  601. //-------------------------------------------------
  602. function cats_tree() {
  603.  
  604. ?>
  605.  
  606. <style type="text/css">
  607.  
  608.   li {
  609.      border:none;
  610.   }
  611.  
  612.    ul {
  613.       width: 300px;
  614.       margin-left: 20px;
  615.       border: solid 1px red;
  616.    }
  617. </style>
  618.  
  619. <?php
  620.     cats_tree_rec(0);
  621. }
  622. //-------------------------------------------------
  623. function cats_tree_rec($parent_id) {
  624.  
  625.     $args = array ( 'orderby'=>'name', 'order'=>'ASC',
  626.        'taxonomy'=>'category', 'hide_empty'=>false, 'parent'=>$parent_id);
  627.  
  628.     $cats = get_categories($args);
  629.  
  630.     if (count($cats)==0)
  631.        return;
  632.  
  633.     echo '<ul>';
  634.     foreach ($cats as $cat) {
  635.         echo '<li>'. $cat->term_id.
  636.        ' <a href="'.get_category_link($cat->term_id).'" target="_blank">'
  637.        .$cat->name.'</a> type='.
  638.         $cat->type.' tax='.$cat->taxonomy.' '.$cat->parent.' '.'</li>';
  639.  
  640.         cats_tree_rec($cat->term_id);
  641.     }
  642.     echo '</ul>';
  643. }
  644. //-------------------------------------------------
  645. function get_cats4() {
  646.    
  647.    $args = array ('type'=>'post', 'orderby'=>'name', 'order'=>'ASC',
  648.        'taxonomy'=>'category');
  649.  
  650.    $cats = get_categories($args);
  651.    //echo '<pre>'.print_r($cats, true).'</pre>';
  652.  
  653.    echo '<ul>';
  654.    foreach ($cats as $cat) {
  655.       echo '<li>'. $cat->term_id. ' '.
  656.       $cat->name. '<br/>'. $cat->slug. '<br/>'. $cat->description. '<br/>'.
  657.      
  658.       $cat->cat_name. '<br/>'.
  659.       $cat->category_nicename.'<br/></li>';
  660.    }
  661.    echo '</ul>';
  662. }
  663. //-------------------------------------------------
  664. function get_posts4() {
  665.  
  666.    $query = new WP_Query(
  667.                         array( 'post_type'=>'post', 'order'=>'DESC')
  668.                     );
  669.  
  670.                     // The Loop
  671.                     while ( $query->have_posts() ) :
  672.                         $query->the_post();
  673.                         $done = '';
  674.                     ?>
  675.  
  676.                         <li data-id="<?php the_id()?>">
  677.  
  678.                             <div>
  679.                                <?php htmlspecialchars(the_title())?>        
  680.                            </div>
  681.                           <?php  get_comms( get_the_id()); ?>
  682.  
  683.                         </li>
  684.                     <?php endwhile; ?>
  685.  
  686. <?php
  687. }
  688.  
  689. //-------------------------------------------------
  690. function get_comms($id) {
  691. $args = array(
  692.  
  693.     'number' => '200',
  694.         'post_id' => $id,
  695.         'order'=>'DESC'
  696.    
  697. );
  698. $comments = get_comments($args);
  699. echo str_repeat('-',40).'<br/>';
  700. foreach($comments as $comment) :
  701.     echo($comment->comment_author .'<br/>'. $comment->comment_author_url.
  702.   '<br />' . $comment->comment_content).'<br/><br/>';
  703. endforeach;
  704. }
  705. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement