How To Download WordPress Audio Attachments

Some people like to stream audio in the browser, others like to download. Each of them is able set up the browser to choose between downloading or streaming different MIME types to get what they need. On the other hand you can force download of certain MIME type files using PHP header() function. See How … Read more

Link post images to post

Yes, don’t use regex for parsing HTML but use DOM instead. This is how I would work it out : In your toolbox, a function to get innerDOM of a node : // GET INNER HTML OF A NODE function DOMinnerHTML($element) { $innerHTML = “”; $children = $element->childNodes; foreach ($children as $child) { $tmp_dom = … Read more

Selecting related posts

if there are no 4 related posts, the code below will fill the number with random posts of random categories, and avoid duplicates: <div class=”my-related-posts”><h4>You may also be interested in…</h4><ul class=”relatedposts”> <?php $duplicates = array( $current_post ); $posts = get_posts( array( “posts_per_page’ => 4, ‘orderby’ => ‘rand’, ‘category’ => $category->term_id, ‘post__not_in’ => array( $current_post )) … Read more

How to split authors?

When you look at the Template hierarchy, then you’ll notice that there’re actual author archives: Archive Page: author-{$nicename}.php >> author-{$id}.php >> author.php This means, that you can simply add an author.php file to your theme and style it whatever you want. The Loop will give you all posts by this author. If you want to … Read more

Have h2 tag not show up if there are no blog posts

Put your <h2> tag after the call to get_related_author_posts(). For example… $rap = get_related_author_posts(); if (!empty($rap)) { echo ‘<h2>Recent Blog Articles</a></h2>’; // <- broken anchor tag !!! echo $rap; // and so on } But you will need to make get_related_author_posts() return false if there are no posts. function get_related_author_posts() { global $authordata, $post; $authors_posts … Read more

Count post view when user open any post

One way to stop this would be to remember if this visitor has seen this page in the last x minutes. You can tackle that in multiple ways: Use a cookie Save visitor IP Use sessions Personally, I find using sessions just for counting pages is a bit silly. Cookies can be a good solution, … Read more

Plotting posts on a graph

You can do that with a custom SQL query, something along the lines of: global $wpdb; $results = $wpdb->get_results( “SELECT DATE(post_date) AS d, COUNT(*) AS c FROM $wpdb->posts WHERE post_status=”publish” GROUP BY d” ); You’ll get an array of objects where d is the date and c is the number of posts published on that … Read more

Is there a way to display others posts in my post?

Without writing code, no – WordPress will not do this. Shouldn’t require much extra code though. Try creating a page called fruit and on it display all posts on it with a category of fruit (you’d have to check the fruit category on the apple and orange posts). You can grab text from another site … Read more