Skip to content

Instantly share code, notes, and snippets.

View kovshenin's full-sized avatar

Konstantin Kovshenin kovshenin

View GitHub Profile
@kovshenin
kovshenin / code1.php
Created July 16, 2011 12:36
WordPress Dashboard Feed Reader
<?php
add_action( 'wp_dashboard_setup', 'my_dashboard_setup' );
function my_dashboard_setup() {
wp_add_dashboard_widget('themefm-dashboard-reader', 'Latest from Theme.fm' , 'my_dashboard_content', $control_callback = null);
}
function my_dashboard_content() {
echo "<p>Dashboard Widget Content</p>";
}
<?php query_posts($query_string . '&cat=-3,-8'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="post">
<!-- Display the Title as a link to the Post's permalink. -->
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<!-- Display the date (November 16th, 2009 format) and a link to other posts by this posts author. -->
<small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></small>
@kovshenin
kovshenin / functions.php
Created July 25, 2011 11:03
Default posts order by name in admin
<?php
/*
* This snippet overrides the default post ordering in the edit posts table (admin),
* while keeping other post ordering options (by clicking on the table headings)
* still available. Useful for CMS-like setups and could be tweaked for
* custom post types as well
*
* Konstantin Kovshenin
* http://theme.fm
*/
@kovshenin
kovshenin / functions.php
Created July 27, 2011 16:19 — forked from vbk/TE-modification
Code used in functions.php
<?php
/** Both color schemes **/
add_filter( 'twentyeleven_color_schemes', 'twentyeleven_color_schemes_both' );
add_action( 'twentyeleven_enqueue_color_scheme', 'twentyeleven_enqueue_color_scheme_both' );
function twentyeleven_color_schemes_both( $color_schemes ) {
$color_schemes['orange'] = array(
'value' => 'orange',
'label' => __( 'Orange', 'twentyeleven' ),
'thumbnail' => get_stylesheet_directory_uri() . '/orange.png',
@kovshenin
kovshenin / style-2.css
Created August 9, 2011 15:13
Twitter Blockquotes Styles
blockquote.tweet {
border-left: solid 4px #ccc;
padding-left: 8px;
}
@kovshenin
kovshenin / one.sql
Created September 28, 2011 09:59
SQL Query
mysql> explain SELECT SQL_CALC_FOUND_ROWS wp_posts.post_title FROM wp_posts INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') AND ( (wp_postmeta.meta_key = 'my-field' AND CONVERT(wp_postmeta.meta_value, CHAR) = 'some value') ) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 10;
+----+-------------+-------------+--------+---------------------------------+----------+---------+---------------------------+------+----------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------------+--------+---------------------------------+----------+---------+---------------------------+------+----------------------------------------------+
| 1 | SIMPLE | wp_postmeta | ref | post_id,meta_k
<?php
class Some_Plugin {
function previous_gallery_post_link() {
add_filter( 'posts_where', array( &$this, 'filter_where_date_lt' ) );
$previous = new WP_Query( array(
'post_type' => 'post',
'tax_query' => array(
'relation' => 'AND',
array(
<?php
function vtp_install_data() {
add_action( 'init', 'vtp_setup_terms', 11 );
}
register_activation_hook( __FILE__, 'vtp_install_data' );
function vtp_setup_terms() {
if ( ! term_exists( 'Customer', 'account_type' ) ) {
wp_insert_term( 'Customer', 'account_type');
function filter_where_this_week( $where ) {
$where .= " AND post_date >= '" . date( 'Y-m-d 00:00:00', strtotime( '-7 days', current_time( 'timestamp' ) ) ) . "' AND post_date < '" . date( 'Y-m-d 23:59:59', strtotime( '+0 days', current_time( 'timestamp' ) ) ) . "' ";
return $where;
}
<select name="account" id="account">
<?php foreach ( $accounts as $account ) :
<option value='<?php echo $account->ID; ?>' <?php selected( in_array( $account->ID ) ); ?> >
<?php echo $account->post_title; ?>
</option>
</select>