Multiple loops in same page, without duplicate content

it is important to read this Codex chapter all the way to the end, as the essential suggestions are after this heading ‘Note for Multiple Posts in the First Category’; repetitive, tedious code: <?php $do_not_duplicate = array(); ?> <?php $mosaics = new WP_Query(‘category_name=mosaics&posts_per_page=5’); ?> <?php while ($mosaics->have_posts()) : $mosaics->the_post(); ?> <?php $do_not_duplicate[] = $post->ID; ?> … Read more

Restrict access to the Trash folder in Posts

With the filter we prevent the Trash link from being printed. And with the action, redirect back to the post listing page if the user tries to access the URL directly (/wp-admin/edit.php?post_status=trash&post_type=post). add_filter( ‘views_edit-post’, ‘wpse_74488_remove_trash_link’ ); add_action( ‘admin_head-edit.php’, ‘wpse_74488_block_trash_access’ ); function wpse_74488_remove_trash_link( $views ) { if( !current_user_can( ‘delete_plugins’ ) ) unset( $views[‘trash’] ); return $views; … Read more

Possible to create a permalink to sort with meta_key?

What about something like that? function wpse139657_orderby(){ if( isset($_GET[‘orderby’]) ){ $order = $_GET[‘order’] or ‘DESC’; set_query_var(‘orderby’, ‘meta_value_num’); set_query_var(‘meta_key’, $_GET[‘orderby’]); set_query_var(‘order’, $order); } } add_filter(‘pre_get_posts’,’wpse139657_orderby’); In this way you can call your urls with a ?orderby=rank suffixed and it should do the trick. You can also have an optional order parameter, should you want to implement … Read more

Show a list of recently viewed posts to a user

This plugin may fulfill your requirements. http://wordpress.org/extend/plugins/recently-viewed-posts Usage get_recently_viewed_posts( $max_shown = 10 ) returns a string of li’s. recently_viewed_posts( $max_shown = 10 ) prints a div If you are interested in learning how to develop this functionality yourself, download the plugin and see the source files. WordPress is Open Source! Update: The above plugin did … Read more

Show post titles only on the homepage

If the posts are already shown on your page, just with a bunch of unnecessary text that you want to take away, do the following: 1. Open the template file of your homepage (it can be named different in different themes, so impossible to give you the exact name of file, but usually they are … Read more

Create A Metabox For A Custom Field

This will create a metabox for you to enter a video code. //Creating a MetaBox for Posts to enter Video Code. add_action(‘add_meta_boxes’,’video_meta_box’); function video_meta_box(){ add_meta_box(‘video_box_id’, ‘Enter Video ‘ , ‘video_box_cb’,’post’,’normal’,’default’); } function video_box_cb($post){ $value = get_post_meta($post->ID,’video_box’,true); echo ‘<textarea rows=”4″ cols=”50″ id=”video_box”, name=”video_box”>’; echo $value; echo ‘</textarea>’; } add_action(‘save_post’,’save_video_box’); function save_video_box($post_id){ $box_data = $_POST[‘video_box’]; update_post_meta($post_id,’video_box’,$box_data); } … Read more

eBooks download website, page or post?

Pages are relatively more static. They don’t change much. Posts on the other hand do change on a regular basis. Just like any store, it’s best to use posts in this case. You can also create a custom post type and call it “ebooks”. It would be more appropriate, but posts can do fine.

Show One Category on Post

Thank you for your question. Try using the following code. <?php $categories = get_the_category(); if($categories[0]) { $url = get_term_link((int)$categories[0]->term_id,’category’); $temp = “<dt><h1>{$categories[0]->name}</h1> </dt><dd>{$categories[0]->category_description}</dd>”; echo “<dl>\n” . $temp . “\n</dl>”; } ?> Best Regards, Vinod Dalvi

How to add padding between posts

WordPress already generates class for each posts, you can use these classes using the post_class function. Note: The function can be used either within the loop or by passing the $post_id So you would have <ul> <?php $the_query = new WP_Query( ‘posts_per_page=5’ ); ?> <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?> <div … Read more