Files: <?php echo $wpdb->get_var( “SELECT COUNT(*) FROM $wpdb->posts WHERE post_parent = ‘$post->ID’ AND post_type = ‘attachment’” ); ?> |
Entries Tagged 'Wordpress Tips And Tricks' ↓
show how many attachments a wordpress post has
January 29th, 2011 — Wordpress Tips And Tricks
How to show the user level in wordpress in the comments
September 30th, 2009 — Wordpress Tips And Tricks
This is how you can show the comment user’s level:
$user = get_userdata($comment->user_id); echo $user->user_level;
how to show all untagged posts in wordpress
July 10th, 2009 — Wordpress Tips And Tricks
over on www.myconfinedspace.com I was having trouble keeping track of which posts had been properly tagged or not. using this code, you’ll be able to display the untagged posts. And edit button will appear when appropriate.
Please note this is a custom page template, so just create a blank text file, rename it “untagged.php” and upload it to your theme directory. then just create a new page through wordpress and tell it to use the “untagged” template!
<?php
/*
Template Name: untagged
*/
?>
<br />
<hr />
<?php
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query(‘showposts=500′.’&paged=’.$paged);
?>
<br />
<div style=”text-align:center;font-size:31px;”>
<?php posts_nav_link(‘ · ‘, ‘previous page’, ‘next page’); ?>
</div>
<br />
<center><?php if(function_exists(‘wp_pagenavi’)) { wp_pagenavi(); } ?></center>
<br />
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php
$tag = get_the_tags();
if (!$tag) { ?>
<a href=”<?php the_permalink() ?>”><?php the_title(); ?>
</a> – - <?php edit_post_link(‘[Edit]‘); ?><br />
<?php
}
endwhile;
endif; ?>
create
please note the large number of posts that will be shown. Since it’s only the post titles that are loading there shouldn’t be a problem with 500 of them at once, but your server may not be the uber powerhouse that mine is
Another quirk of this bit of code is that each page is 500 posts of your material, and it only shows the ones that are untagged. so if you have untagged posts that are 4,000 posts back, you’ll need to click over to page 8 or 9 to see those posts pop up on this.
how to list your future posts in wordpress
July 10th, 2009 — Wordpress Tips And Tricks
Want to show what posts are coming up? add this bit of code in:
$my_query = new WP_Query('post_status=future&showposts=1000&order=asc');
?>
why won’t my wp_query work in wordpress?
July 10th, 2009 — Wordpress Tips And Tricks
I’ve had it happen a few times that my custom queries and even some of the ‘ishome’ or ‘isfrontpage’ queries weren’t working correctly. before you pull your hair out, try adding this immediately before your query:
Show the first image of a specific post in wordpress
July 10th, 2009 — Wordpress Tips And Tricks
not exactly sure why I was looking to do this, but here it is anyways:
note that you’ll need to have added the ‘list_first_image’ bit to your functions.php file.
wordpress – how to show first attachment
July 10th, 2009 — Wordpress Tips And Tricks
add this to your theme’s “functions.php” page:
function list_first_image() {
$files = get_children('post_parent='.get_the_ID().'&post_type=attachment&post_mime_type=image');
if($files) :
$keys = array_reverse(array_keys($files));
$j=0;
$num = $keys[$j];
$image=wp_get_attachment_image($num, 'large', false);
$imagepieces = explode('"', $image);
$imagepath = $imagepieces[1];
$thumb=wp_get_attachment_thumb_url($num);
print " '$thumb' ";
endif;
}
alternatively you can also pass along some size requirements. this is the one that’s in use under each ‘single post’ on www.myconfinedspace.com :
function get_first_image() {
$files = get_children('post_parent='.get_the_ID().'&post_type=attachment&post_mime_type=image');
if($files) :
$keys = array_reverse(array_keys($files));
$j=0;
$num = $keys[$j];
$image=wp_get_attachment_image($num, 'large', false);
$imagepieces = explode('"', $image);
$imagepath = $imagepieces[1];
$thumb=wp_get_attachment_thumb_url($num);
print "";
endif;
}
once you have either of those added to your functions.php file, you can call them using :
or
How to show a number of random posts in wordpress
July 10th, 2009 — Wordpress Tips And Tricks
Code markup test
July 10th, 2009 — Wordpress Tips And Tricks
code markup test:
I’m going to be using the most excellent code mark up plugin in the posts here. you can learn more about this plugin here : wordpress.org/extend/plugins/code-markup/
Warning: include(/var/www/vhosts/wordpress/wp-content/themes/copyblogger/navigation.php) [function.include]: failed to open stream: No such file or directory in /var/www/vhosts/wordpress/wp-content/themes/copyblogger/archive.php on line 30
Warning: include() [function.include]: Failed opening '/var/www/vhosts/wordpress/wp-content/themes/copyblogger/navigation.php' for inclusion (include_path='.:') in /var/www/vhosts/wordpress/wp-content/themes/copyblogger/archive.php on line 30