3 new code snippets
Protecting blog media
If you do not want the blog author to see those media files, which they did not upload, you can add the following code to your functions.php file.
1 2 3 4 5 6 7 8 9 |
function my_files_only( $wp_query ) { if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/upload.php' ) !== false ) { if ( !current_user_can( 'level_5' ) ) { global $current_user; $wp_query->set( 'author', $current_user->id ); } } } add_filter('parse_query', 'my_files_only' ); |
Output of articles for a certain period
We display a list of articles in the admin panel according to a certain condition. Just add the code to the theme's functions.php file. In this case, we display posts for a certain period of time..
1 2 3 4 5 6 7 8 9 10 11 12 |
<?php function filter_where($where = '') { $where .= " AND post_date >= '1980-05-11' AND post_date <= '2011-05-11'"; return $where; } add_filter('posts_where', 'filter_where'); query_posts($query_string); while (have_posts()) : the_post(); the_content(); endwhile; ?> |
A quick way to create multiple sitebars.
For quick creation, add a code snippet to the functions.php file, which will create multiple sidebars in a loop.
1 2 3 4 5 6 7 8 9 10 11 12 |
if ( function_exists('register_sidebar') ) { $allWidgetizedAreas = array("Homepage Left", "Homepage Right", "Sidebar One", "Movies", "Admin"); foreach ($allWidgetizedAreas as $WidgetAreaName) { register_sidebar(array( 'name'=> $WidgetAreaName, 'before_widget' => '<div id="%1$s" class="widget %2$s left half">', 'after_widget' => '</div>', 'before_title' => '<h3 class="widgettitle">', 'after_title' => '</h3>', )); } } |
/*
- Basic web design course;
- Site layout;
- General course on CMS WordPress and continuation of the course on template development;
- Website development in PHP.