you are in: codestackercodes [RSS] → tag: wordpress [RSS]

wordpress: posting via php Delicious Email

via http://codex.wordpress.org/Function_Reference/wp_insert_post

show/hide lines
   1  <?php
   2  
   3  	include "wp-blog-header.php";
   4  
   5  	$my_post = array();
   6  	$my_post['post_title'] = 'My post';
   7  	$my_post['post_content'] = 'This is my post.';
   8  	$my_post['post_status'] = 'publish';
   9  	$my_post['post_author'] = 1;
  10  	$my_post['post_category'] = array(13);
  11  
  12  	$post_id = wp_insert_post($my_post);
  13  
  14  	$post = get_post($post_id);
  15  	wp_redirect($post->guid);
  16  
  17  ?>
created by leozera — 20 April 2011 — get a short url — tags: php wordpress embed

display popular posts (most commented) Delicious Email

show/hide lines
   1  <?php $result = $wpdb->get_results("SELECT comment_count,ID,post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , 10");
   2  foreach ($result as $topten) {
   3  $postid = $topten->ID;
   4  $title = $topten->post_title;
   5  $commentcount = $topten->comment_count;
   6  if ($commentcount != 0) { ?>
   7  <li><a href="<?php echo get_permalink($postid); ?>" title="<?php echo $title ?>"><?php echo $title ?></a></li>
   8  <?php } } ?>
created by leozera — 18 April 2011 — get a short url — tags: php wordpress embed

display recent updated posts/pages Delicious Email

show/hide lines
   1  <?php
   2  	$today = current_time('mysql', 1);
   3  	$howMany = 5; // Number of posts you want to display
   4  	if ( $recentposts = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts WHERE post_status = 'publish' AND post_modified_gmt < '$today' ORDER BY post_modified_gmt DESC LIMIT $howMany")):
   5  ?>
   6  <ul>
   7  <?php
   8  foreach ($recentposts as $post) {
   9  	if ($post->post_title == '') $post->post_title = sprintf(__('Post #%s'), $post->ID);
  10  	echo "<li><a href='".get_permalink($post->ID)."'>";
  11  	the_title();
  12  	echo '</a></li>';
  13  }
  14  ?>
  15  </ul>
  16  <?php endif; ?>
created by leozera — 17 April 2011 — get a short url — tags: php wordpress embed

display rss using wordpress Delicious Email

show/hide lines
   1  <?php 
   2  	include_once(ABSPATH.WPINC.'/rss.php');
   3  	wp_rss('http://mysite.com/feed', 5); 
   4  ?>
created by leozera — 17 April 2011 — get a short url — tags: php rss wordpress embed

display recent posts Delicious Email

show/hide lines
   1  <?php query_posts('showposts=5'); ?>
   2  <ul>
   3  <?php while (have_posts()) : the_post(); ?>
   4  <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
   5  <?php endwhile;?>
   6  </ul>
created by leozera — 17 April 2011 — get a short url — tags: php wordpress embed

count search results Delicious Email

show/hide lines
   1  Results for: <?php $allsearch = &new WP_Query("s=$s&showposts=-1"); $key = wp_specialchars($s, 1); $count = $allsearch->post_count; echo $key . ' (' . $count . ')'; wp_reset_query(); ?>
created by leozera — 17 April 2011 — get a short url — tags: php wordpress embed

reset wordpress admin password via sql Delicious Email

show/hide lines
   1  UPDATE wp_users
   2  SET user_pass = MD5('password')
   3  WHERE user_login = 'login';
created by leozera — 17 April 2011 — get a short url — tags: sql wordpress embed

disable post revisions Delicious Email

in your /wp-config.php

show/hide lines
   1  <?php
   2  
   3  define('WP_POST_REVISIONS', false);
   4  
   5  ?>
created by leozera — 17 April 2011 — get a short url — tags: php wordpress embed

delete post revisions Delicious Email

show/hide lines
   1  DELETE a,b,c  
   2  FROM wp_posts a  
   3  LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id)  
   4  LEFT JOIN wp_postmeta c ON (a.ID = c.post_id)  
   5  WHERE a.post_type = 'revision'
created by leozera — 17 April 2011 — get a short url — tags: sql wordpress embed

page x of y in wordpress Delicious Email

based on http://design.sparklette.net/teaches/how-to-add-wordpress-pagination-without-a-plugin/

show/hide lines
   1  <?php
   2  
   3  // paste in functions.php
   4  
   5  function pagination($pages = '', $range = 4){
   6       $showitems = ($range * 2)+1;  
   7  
   8       global $paged;
   9       if(empty($paged)) $paged = 1;
  10  
  11       if($pages == '') {
  12           global $wp_query;
  13           $pages = $wp_query->max_num_pages;
  14           if(!$pages) {
  15               $pages = 1;
  16           }
  17       }   
  18  
  19       if(1 != $pages) {
  20           echo "Page ".$paged." of ".$pages;
  21       }
  22  }
  23  
  24  ?>
  25  
  26  
  27  
  28  <?php
  29  
  30  // in your template 
  31  
  32  if (function_exists("pagination")) { pagination($additional_loop->max_num_pages); } 
  33  
  34  ?>
created by leozera — 14 April 2011 — get a short url — tags: php wordpress embed
Displaying records 1 - 10 of 19