Before we continue, I must point out this:
$i=1;
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query();
$wp_query -> query('post-format-audio'.'&paged='.$paged)
This is exactly the same as:
query_posts( 'post-format-audio'.'&paged='.$paged );
Which is terrible. When people advise against using query_posts
, it’s not just the function that’s bad, it’s what it does.
Thankfully someone told you about WP_Query
, but they didn`t finish the job.
This is what your query loop should really look like:
$args = array(
'post_format' => 'post-format-audio'
);
$q = new WP_Query( $args );
if ( $q->have_posts() ) {
while( $q->have_posts() ) {
$q->the_post();
the_title(); // etc
}
wp_reset_postdata(); // clean up after ourselves
}
The important part being that post formats are saved as a custom taxonomy internally, with a taxonomy name of ‘post_format’.
But even this is bad!
I saw in your original code you completely discard the original main query ( yet another reason query_posts
is terrible ). What you should have done instead, is used the pre_get_posts
filter to modify the main query before it runs, so that you don’t have to discard it and waste time and slow down your page. This way also gives you all the pagination and other things that Core does for free.
So if this is your home page, you could do this:
function audio_only( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'post_format', 'post-format-audio' );
}
}
add_action( 'pre_get_posts', 'audio_only' );
With that in a plugin or functions.php
your homepage will only show posts with the audio post format. You can override individual term archives, searches, RSS feeds etc using this, anywhere that has a main loop.
But that’s still not the best way of doing this. WordPress automatically gives you a post format archive for free! You can even use a special template file for it. So there’s no need to build an audio format archive, there’s already one there
Further Reading
Final Notes
echo do_shortcode("$myvalue");
is wasteful, there’s no need for the quotes, useecho do_shortcode( $myvalue );
instead, it’s a little faster to type and friendlier for editors and code intel- I know the codex uses it, but don’t bother with
if(): while() : the_post();
, instead use brace brackets{}
and move them on to their own lines. 1 statement/command per line. Again it’s easier to read, and far nicer for automated tools and editors, and we all need all the help we can get so we can focus on the important stuff - All those corner span elements
<span class="top-left-corner"></span>
could be removed and replaced with multiple CSS backgrounds,border-radius
, or:after
and:before
css selectors