Advertisement
terorama

WP / API Usage Example

May 29th, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.17 KB | None | 0 0
  1. <?php
  2. //------------------------------------------------------------------------
  3. //------------------------------------------------------------------------
  4. echo '<h3>list of blog post types</h3>';
  5.  
  6. $post_types = get_post_types (array(),'names');
  7. echo implode(',',$post_types);
  8.  
  9.  
  10. echo '<h2>list of blog taxonomies</h2>';
  11.  
  12. $taxz = get_taxonomies(array(), 'objects');
  13.  
  14. foreach ($taxz as $tax) {
  15.    echo '<h3>'.$tax->name.'</h3>';
  16.  
  17.    $terms = get_terms($tax->name, array('hide_empty'=>false,'parent'=>0));
  18.    echo '<ul>';
  19.    foreach ($terms as $term) {
  20.       echo $term->term_id.'<br/>';
  21.    
  22.       echo '<li><a href="'.get_term_link((integer)$term->term_id, $tax->name).
  23. '" target="_blank">'.
  24.      $term->name.' ('.$term->count.')</a></li>';
  25.  
  26.      $subterms = get_term_children($term->term_id, $tax->name);
  27.      
  28.      echo '<ol>';
  29.      foreach ($subterms as $id) {
  30.  
  31.         $subterm = get_term($id, $tax->name);
  32.         echo '<li>'.$subterm->term_id.' <a href="'.
  33. get_term_link((integer)$subterm->term_id, $tax->name).
  34.               '" target="_blank">'.$subterm->name.'</a> ('.$subterm->count.')</li>';
  35.      }
  36.      echo '</ol>';
  37.      
  38.    }
  39.    echo '</ul>';
  40.    
  41. }
  42. //------------------------------------------------------------------------
  43. //------------------------------------------------------------------------
  44. <?php
  45. //-------------------------------------------------
  46. define('WP_USE_THEMES', false);
  47. require('../wp-load.php');
  48. header('Content-type: text/html; charset=utf-8');
  49. //-------------------------------------------------
  50. @ini_set('display_errors',true);
  51.  
  52.  
  53.  
  54. //---------------------------------
  55. $cats = get_categories(array('parent'=>get_cat_id('Блог')));
  56.  
  57. foreach ($cats as $cat) {
  58.    echo '<h3>'.$cat->name.' ('.get_category_parents($cat->term_id).')</h3>';
  59.    echo '<a href="'.get_term_link((integer)$cat->term_id,'category').'">go to</a><br/>';
  60.  
  61.    $posts = get_posts(array('category'=>$cat->term_id));
  62.    echo '<ul>';
  63.    foreach ($posts as $post) {
  64.      
  65.       setup_postdata($post);
  66.       echo '<li>'.get_post_status(get_the_id());
  67.  
  68.       if (has_post_thumbnail(get_the_id())) {
  69.          echo get_the_post_thumbnail(get_the_id(),'thumbnail');
  70.       }
  71.       echo '<a href="'.get_permalink().'" target="_blank">'.
  72.        get_the_title().'</a> ';
  73.        
  74.        $author = $post->post_author;
  75.        $author4 = get_user_by('id', $author);
  76.  
  77.        $author_url = get_author_posts_url($author);
  78.        echo '<a href="'.$author_url.'" target="_blank">'.$author4->display_name.
  79.           '</a> '.get_the_date('d.m.Y H:i:s',get_the_id());
  80.  
  81.         echo '<br/>comments<br/>';
  82.  
  83.         comments_popup_link( 'No comments yet', '1 comment', '% comments',
  84.       'comments-link',     'Comments are off for this post');
  85.  
  86.        if ($post->comment_count>0) {
  87.           $comments = get_comments (array('post_id'=>get_the_id(), 'number'=>4));
  88.           echo '<ol>';
  89.           foreach ($comments as $comment) {
  90.              echo '<li>';
  91.              echo get_avatar($comm, 32).' ';
  92.              echo '<a href="'.get_author_posts_url($comment->user_id).'" target="_blank">';
  93.              echo $comment->comment_author.'</a> '.$comment->comment_content.
  94.              ' '.$comment->comment_date;
  95.              echo '</li>';
  96.           }
  97.           echo '</ol>';
  98.        }
  99.        echo '<br/>attachments<br/>';
  100.  
  101.        $atts = & get_children (array('post_type'=>'attachment','post_parent'=>get_the_id()));
  102.        echo '<ol>';
  103.        foreach ($atts as $att) {
  104.           if (wp_attachment_is_image($att->ID)) {
  105.              $src = wp_get_attachment_image_src($att->ID,'large');
  106.              echo '<li>'.$att->post_title.' '.$att->post_mime_type.
  107.              '<a href="'.$src[0].'" target="_blank">'.
  108.               wp_get_attachment_image($att->ID, 'thumbnail').'</a></li>';
  109.           }
  110.        }
  111.        echo '</ol>';
  112.  
  113.        echo get_the_term_list(get_the_id(),'category','<ul><li>','</li><li>','</li></ul>');
  114.        echo get_the_tag_list ('<ul><li>','</li><li>','</li></ul>');
  115.  
  116.        echo '<br/>edit block<br/>';
  117.        echo get_edit_post_link(get_the_id());
  118.        echo get_delete_post_link(get_the_id());
  119.       echo '</li>';
  120.    }
  121.    echo '</ul>';
  122.    
  123. }
  124.  
  125. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement