Jump to content
Sign in to follow this  
dacree

Randomizing Posts in Content Area

Recommended Posts

dacree

Not sure if this is a definable function in the theme options, but I would like to randomize what posts appear in the main content area. And in fact, would like to limit which categories are accessed as well. I can use POST QUERY plug-in to accomplish this in a sidebar, but do not understand how this is done to control the center content area.

Share this post


Link to post
Share on other sites
cmunns

You would use a hook to query_posts before the loop. In your functions.php file add something like ` add_action('pagelines_before_theloop','my_query'); function my_query(){ query_posts('cat=-1&orderby=rand'); } ` This isn't tested and will have to be refined. The -1 will exclude that category ID.

Share this post


Link to post
Share on other sites
dacree

Worked! Thanks. Looking at all of that code is a bit scary, but I figure all I have to do is take it out again if something goes wrong. Just knowing where to place the suggested code is a little nerve-racking. Here for the reference of someone with as little knowledge as me is a larger snippet of where this was placed in the Pageline Base, Theme Functions (functions.php) file. // HOOKS EXAMPLE --------// // Below is an example of how you would add a social media icon to the icons in header (branding section) // We have placed a hook at the end of the icon set specifically add new icons without modifying code or having to worry about your edits // getting thrown out during the upgrade process. The way to use hooks goes a little like this: // add_action('hook_name','function name'); // ---> uncomment to load //add_action('pagelines_branding_icons_end', 'add_icons_to_branding'); // function name function add_icons_to_branding(){ // This hook adds a stumbleupon icon to the header of your theme. The class referenced in the link can be seen in the style.css // and is the image from the CSS is placed in the images folder ?> <?php } // end function //my custom code follows `add_action('pagelines_before_theloop','my_query'); function my_query(){ query_posts('cat=-172&orderby=rand'); }` //Note that I have indicated that Category 172 be OMITTED by having put the - sign before the category number. I suppose I could have other category numbers by just adding commas. Correct me if this is wrong.

Share this post


Link to post
Share on other sites
dacree

Sorry, I jumped the gun on thinking this issue was resolved. While the code absolutely DOES ramdonize the posts in my contents area, it also forces randomization for any post. If a user searches for a particular post, it will not be displayed. Seems that is because it is replaced with a random post before the searched for post can be displayed. I say this because the searched for post appears in the breadcrumb display.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

×