TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-18-2008, 04:10 AM   #1 (permalink)
Dan
The Wanderer
 
Dan's Avatar
 
Join Date: Dec 2007
Location: England
Posts: 15
Thanks: 6
Dan is on a distinguished road
Default Wordpress Questions

Hello,

These have been bugging me for a while and I've not been able to find a solution to nether:

1) Display the total number of wordpress posts, minus a category. So all posts within all category's apart from 1.

2) Display a set number of random posts on a single page.

I know these can most likely be done using a plugin but the way i want to use them isn't worth having a plugin for.

Can anyone help?
Dan is offline  
Reply With Quote
Old 01-18-2008, 10:15 AM   #2 (permalink)
The Frequenter
 
ReSpawN's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
ReSpawN is on a distinguished road
Default

Hello Dan. First off, welcome to talkPHP

From my brief experience with Wordpress, I know that there are a LOT of plugins available. Even on these nagging points.

#1. I've annoyed myself from time to time with that one as well, but I never figured out where I could change or somehow edit the code. There might be something on their site about the maximum post count.

#2. Try the random post plugin. If I remember correctly, that's what it's called. Else you can of course retrieve the array of posts and then randomly display one each time the page refreshes. If you look closely, Wildhoney (talkPHP meister) did the same thing with some random tips on PHP as well.

I hope my post satisfies you. If not, you can wait till some Wordpress guru replied here. To my knowledge, nobody here uses Wordpress but somehow I figure that Alan @ CIT en Rendair have used it in the past. They simply strike me as Wordpress users. Don't ask why tho.

Good luck and I hope to see you around the forum some more. Enjoy your stay.
__________________
"Life is a bitch, take that bitch on a ride"
Send a message via MSN to ReSpawN
ReSpawN is offline  
Reply With Quote
Old 01-18-2008, 12:04 PM   #3 (permalink)
The Frequenter
Prolific Welcomer Upcoming Programmer 
 
Join Date: Sep 2007
Posts: 360
Thanks: 24
Haris is on a distinguished road
Default

Placeholder for my post. (I'll reply with solution).
__________________
Necessity is the mother of invention.

My blog
Haris is offline  
Reply With Quote
Old 01-18-2008, 05:08 PM   #4 (permalink)
Dan
The Wanderer
 
Dan's Avatar
 
Join Date: Dec 2007
Location: England
Posts: 15
Thanks: 6
Dan is on a distinguished road
Default

Still trying to display random posts in wordpress, I have this working with the follwing:
Code:
<?php global $wpdb; $numposts = 40;
            $rand_posts = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' AND  post_category != 1 ORDER BY RAND() LIMIT $numposts");
            foreach($rand_posts as $post) : setup_postdata($post);

            $title = $wp_query->post->post_title; $str = strtolower($title); $newtitle = str_replace(" ", "-", $str); ?>
            <a href="<?php the_permalink() ?>" title="<?php the_title(); ?> Wallpaper"><img src="<?php echo get_option('siteurl'); ?>/images/160x120/<?php echo $newtitle ?>.jpg" alt="<?php the_title(); ?>" /></a>
            <?php endforeach; ?>
However I want to exclude a category from getting pulled up. That category is the wordpress default - cat_ID=1.

Any suggestions?

Last edited by Dan : 01-18-2008 at 05:31 PM.
Dan is offline  
Reply With Quote
Old 01-18-2008, 07:17 PM   #5 (permalink)
The Frequenter
Prolific Welcomer Upcoming Programmer 
 
Join Date: Sep 2007
Posts: 360
Thanks: 24
Haris is on a distinguished road
Default

Quote:
Originally Posted by Dan View Post
Still trying to display random posts in wordpress, I have this working with the follwing:
Code:
<?php global $wpdb; $numposts = 40;
            $rand_posts = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' AND  post_category != 1 ORDER BY RAND() LIMIT $numposts");
            foreach($rand_posts as $post) : setup_postdata($post);

            $title = $wp_query->post->post_title; $str = strtolower($title); $newtitle = str_replace(" ", "-", $str); ?>
            <a href="<?php the_permalink() ?>" title="<?php the_title(); ?> Wallpaper"><img src="<?php echo get_option('siteurl'); ?>/images/160x120/<?php echo $newtitle ?>.jpg" alt="<?php the_title(); ?>" /></a>
            <?php endforeach; ?>
However I want to exclude a category from getting pulled up. That category is the wordpress default - cat_ID=1.

Any suggestions?
PHP Code:
$wpdb->get_results("SELECT * FROM wp_posts, wp_term_taxonomy, wp_term_relationships WHERE wp_posts.post_type = 'post' AND wp_posts.post_status = 'publish' AND wp_term_taxonomy.taxonomy = 'category' AND wp_term_taxonomy.term_id != 1 AND wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id AND wp_posts.ID = wp_term_relationships.object_id ORDER BY RAND()"
That'll help ya generate random posts.
__________________
Necessity is the mother of invention.

My blog
Haris is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 09:44 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design