Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar Mark Forums Read
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 06-25-2013, 02:43 AM   #1
nexcom28
So Fucking Banned
 
Join Date: Jan 2005
Posts: 3,716
Need Wordpress Help

I did try searching but can't find the answer.

I am just wanting to make a small change to one of my category pages however I don't have a category.php file

Aside from category.php or archive.php where else might I make this change?

I have

entry.php
navigation.php
functions.php
postinfo.php
scripts.php

And a few more
nexcom28 is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-25-2013, 03:08 AM   #2
Pink Misfit
xXxAffiliateReviews.com
 
Pink Misfit's Avatar
 
Industry Role:
Join Date: Jun 2007
Location: US
Posts: 1,035
What are you wanting to change?
__________________
Available for VA assistance, customer service, sales and support, content writer, etc!

Contact: [email protected]
Pink Misfit is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-25-2013, 03:17 AM   #3
nexcom28
So Fucking Banned
 
Join Date: Jan 2005
Posts: 3,716
I am wanting random posts from one category only

Looking to put this code in
Code:
query_posts(array(
	'showposts' => 6,
	'orderby' => 'rand',
	'category_name' => 'News' //You can insert any category name
));
if (have_posts()) : while (have_posts()) : the_post();
or something similar.

Really I just want to randomise the posts from one category. I would use a pplugin but I can't find one, they all seem to be widgets.
nexcom28 is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-25-2013, 03:34 AM   #4
vdbucks
Monger Cash
 
Industry Role:
Join Date: Jul 2010
Posts: 2,773
Quote:
Originally Posted by nexcom28 View Post
I am wanting random posts from one category only

Looking to put this code in
Code:
query_posts(array(
	'showposts' => 6,
	'orderby' => 'rand',
	'category_name' => 'News' //You can insert any category name
));
if (have_posts()) : while (have_posts()) : the_post();
or something similar.

Really I just want to randomise the posts from one category. I would use a pplugin but I can't find one, they all seem to be widgets.
if you have a home.php file, copy it and rename the copy to category.php. If you have no home.php file then copy index.php and rename the copy to category.php.

You would then need to strip out any existing query args from the new category.php file you created, and replace it with something like this:

Code:
query_posts($query_string."&showposts=6&orderby=rand")
I wouldn't recommend inserting the "'category_name' => 'News'" part because the category.php file is global and will cover any and all categories via "$query_string" in my example.

Last edited by vdbucks; 06-25-2013 at 03:38 AM..
vdbucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-25-2013, 03:42 AM   #5
nexcom28
So Fucking Banned
 
Join Date: Jan 2005
Posts: 3,716
I found this in entry.php
Code:
query_posts($args);
	}
?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
Which I presume is the right place, I tried to add
Code:
query_posts(array(
        'showposts' => 6,
	'orderby' => 'rand',
	'category_name' => 'news' //You can insert any category name
));
	}
?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
But it didn't make any differece.
nexcom28 is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-25-2013, 03:45 AM   #6
nexcom28
So Fucking Banned
 
Join Date: Jan 2005
Posts: 3,716
Thanks for this vd but there isn't a query args in home.php
nexcom28 is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-25-2013, 03:55 AM   #7
vdbucks
Monger Cash
 
Industry Role:
Join Date: Jul 2010
Posts: 2,773
Quote:
Originally Posted by nexcom28 View Post
Thanks for this vd but there isn't a query args in home.php
Then simply add the following right before the "if (have_posts())" [or "while (have_posts())" if there is no if] line:
Code:
query_posts($query_string."&showposts=6&orderby=rand")
vdbucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-25-2013, 04:01 AM   #8
nico-t
emperor of my world
 
Join Date: Aug 2004
Location: nethalands
Posts: 29,903
this works for me:

Code:
			<?php
			global $post;
			$myposts = get_posts('numberposts=6&category=3&orderby=rand');
			foreach($myposts as $post) :
			setup_postdata($post); ?>

					<?php
					global $more;
					$more = 0;
					?>

			<div class="postboxmain" id="post-<?php the_ID(); ?>">
			REST OF YOUR POST TEMPLATE HERE
			</div>

			<?php endforeach; 
			wp_reset_query(); 
			?>
nico-t is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-25-2013, 04:05 AM   #9
vdbucks
Monger Cash
 
Industry Role:
Join Date: Jul 2010
Posts: 2,773
Quote:
Originally Posted by nico-t View Post
this works for me:

Code:
			<?php
			global $post;
			$myposts = get_posts('numberposts=6&category=3&orderby=rand');
			foreach($myposts as $post) :
			setup_postdata($post); ?>

					<?php
					global $more;
					$more = 0;
					?>

			<div class="postboxmain" id="post-<?php the_ID(); ?>">
			REST OF YOUR POST TEMPLATE HERE
			</div>

			<?php endforeach; 
			wp_reset_query(); 
			?>
Unless you're running a loop inside of a loop, or working directly with a wpdb query then there is absolutely no reason to use a foreach loop...
vdbucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-25-2013, 04:07 AM   #10
nico-t
emperor of my world
 
Join Date: Aug 2004
Location: nethalands
Posts: 29,903
Quote:
Originally Posted by vdbucks View Post
Unless you're running a loop inside of a loop, or working directly with a wpdb query then there is absolutely no reason to use a foreach loop...
I have no idea about the technical stuff, all i know is it works
nico-t is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-25-2013, 04:13 AM   #11
vdbucks
Monger Cash
 
Industry Role:
Join Date: Jul 2010
Posts: 2,773
Quote:
Originally Posted by nico-t View Post
I have no idea about the technical stuff
I'm aware of that :P

I was just letting you, and the OP know heh
vdbucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-25-2013, 04:18 AM   #12
vdbucks
Monger Cash
 
Industry Role:
Join Date: Jul 2010
Posts: 2,773
For the OP, here is an example of what one of my category.php files looks like... ignore the html parts of course if you're going to use it:

Code:
<?php get_header(); ?>

  <div class="large-9 columns">
    <header class="site-header" role="banner">
      <img src="/assets/img/header/<?php echo rand(1,15) ?>.jpg" />
    </header>
      <?php
        if ( get_query_var('paged') ) { $paged = get_query_var('paged'); }
        elseif ( get_query_var('page') ) { $paged = get_query_var('page'); }
        else { $paged = 1; }

        query_posts($query_string."&showposts=30") 
      ?>
        <!-- Main Content -->
        <h3 class="sectionTitle"><?php wp_title(''); ?></h3>
        <ul class="small-block-grid-1 large-block-grid-3">
          <?php 
            if ( have_posts() ) :
              while ( have_posts() ) : the_post();
                if (is_user_logged_in()) {
                  get_template_part('templates/members/content', 'tpgrid');
                } else {
                  get_template_part('templates/tour/content', 'tpgrid');
                }
              endwhile; 
            endif; 
          ?>
        </ul>
        <?php if ( $wp_query->max_num_pages > 1 ) : // if there's more than one page turn on pagination ?>
            <?php wp_pagenavi(); ?>
        <?php endif; ?>

        <!-- End Main Content -->

    </div><!-- End large-9 -->
<?php if (is_user_logged_in()) { get_sidebar('members'); } else { get_sidebar('tour'); } ?>
<?php get_footer(); ?>
vdbucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-25-2013, 04:26 AM   #13
nexcom28
So Fucking Banned
 
Join Date: Jan 2005
Posts: 3,716
I hate messing with themes, I tried adding the code you suggested so it looked like

Code:
<?php query_posts($query_string."&orderby=rand") if (have_posts()) : while (have_posts()) : the_post(); ?>
I took out the 6 posts bit.

Unfortunately it generated a syntax parse error.

Think I will just leave it.
nexcom28 is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-25-2013, 04:32 AM   #14
vdbucks
Monger Cash
 
Industry Role:
Join Date: Jul 2010
Posts: 2,773
Quote:
Originally Posted by nexcom28 View Post
I hate messing with themes, I tried adding the code you suggested so it looked like

Code:
<?php query_posts($query_string."&orderby=rand") if (have_posts()) : while (have_posts()) : the_post(); ?>
I took out the 6 posts bit.

Unfortunately it generated a syntax parse error.

Think I will just leave it.
You forgot a ; after the query_posts argument... Use the following:

Code:
<?php query_posts($query_string."&orderby=rand"); if (have_posts()) : while (have_posts()) : the_post(); ?>
vdbucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-25-2013, 04:40 AM   #15
nexcom28
So Fucking Banned
 
Join Date: Jan 2005
Posts: 3,716
Thanks for your help, it's actually working now but it's displaying all posts random. How do I edit that to only display random posts from a specific category?
nexcom28 is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-25-2013, 04:52 AM   #16
vdbucks
Monger Cash
 
Industry Role:
Join Date: Jul 2010
Posts: 2,773
Quote:
Originally Posted by nexcom28 View Post
Thanks for your help, it's actually working now but it's displaying all posts random. How do I edit that to only display random posts from a specific category?
Could you elaborate on what you want exactly?

Do you want only a single category of posts to be shown on the categories page? Doing this would render all other category links and pages inoperable if going this route.

Do you want to have a fully functional category page that will work with all links and posts on your site and only want posts in the "News" category to display randomly?

Do you want a separate page for "News"?

There are various ways your question can be interpreted, and many answers depending on what you want specifically so I need a little more info before I offer a solution.
vdbucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-25-2013, 05:09 AM   #17
nexcom28
So Fucking Banned
 
Join Date: Jan 2005
Posts: 3,716
I have several categories, one of them being for example 'news'. I am wanting to random the posts within this category only.

Currently all posts in all categories are random.

Thanks
nexcom28 is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-25-2013, 05:16 AM   #18
vdbucks
Monger Cash
 
Industry Role:
Join Date: Jul 2010
Posts: 2,773
Quote:
Originally Posted by nexcom28 View Post
I have several categories, one of them being for example 'news'. I am wanting to random the posts within this category only.

Currently all posts in all categories are random.

Thanks
I think the best way for that then would be to copy category.php to category-news.php (make sure the "news" portion matches the category slug), or to category-ID.php (where ID = the news category ID). You can find the info you need in wp-admin -> Posts -> Categories.

Then, just remove the "query_posts($query_string."&orderby=rand");" from the base category.php file, and you should be good to go.

And then, for any other categories you may want to display random posts for in the future, simply copy category-news.php (or category-ID.php) to category-slug.php (or category-ID.php, again specifying the numeric ID of said category).

More info here: http://codex.wordpress.org/Category_Templates
vdbucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-25-2013, 08:35 AM   #19
All1
So Fucking Banned
 
Industry Role:
Join Date: May 2013
Posts: 215
Fuck with the usernames.
All1 is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks
Thread Tools



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.