Wordpress Themes - WP Forum at BFA
Click here to register or to donate.
Auto self-registration is not available here - far too many spammers. This forum has many, many backlinks and because of that there is an intense desire among spammers to drop their links here.

Wordpress Themes - WP Forum at BFA » WordPress Themes » Montezuma Theme »

[SOLVED] How to have random posts only on index page (not category, author...)?


  #1  
Old Jun 19, 2013, 01:59 AM
fususu
 
2 posts · Jun 2013
At first, thanks for great theme

I'm working on an interesting online image-dictionary project (http://phut59.com), and I want to have random word on the index page. After a few searches I did it by adding a php code in function bfa_loop() in template_tags.php to query random posts.

Code:
function bfa_loop( $postformat = 'postformat' ) {

	query_posts($query_string . '&orderby=rand'); <!-- here is the code i added -->
	
	if( have_posts() ) : ?>
		
	<div class="post-list">
	<?php while (have_posts()) : the_post(); ?>
		<?php bfa_get_template_part( $postformat, get_post_format() ); ?>		
	<?php endwhile; ?>
	</div>
...
And it worked, I have random posts on the index page, but it does also to the category and author page too. After that, I figured out the category and author page use the same main template index.php. So I guess that to have normal posts in category (or author page) I must create a new main template "category.php" then make a another loop function like this in template_tags.php

Code:
function bfa_loop_norandom( $postformat = 'postformat' ) {
	
	if( have_posts() ) : ?>
		
	<div class="post-list">
	<?php while (have_posts()) : the_post(); ?>
		<?php bfa_get_template_part( $postformat, get_post_format() ); ?>		
	<?php endwhile; ?>
	</div>
...
Then call it in the category.php main template.

Code:
<!--<div id="container">-->
<?php get_header(); ?>
<div id="main" class="row">
	<div id="content" class="cf col8">

      
    <?php bfa_loop_norandom( 'postformat' );  ?>
 			
	</div>
	
	<div id="widgetarea-one" class="col4">
		<?php dynamic_sidebar( 'Widget Area ONE' ); ?>
	</div>

</div>
<?php get_footer(); ?>

<!--</div>-->
But it did not work, there was nothing on category page (for example http://phut59.com/category/tu-sieu-de/) . It seemed the new function I added not work.

I wonder if someone can help.

Thanks in advance
  #2  
Old Jun 19, 2013, 04:14 AM
fususu
 
2 posts · Jun 2013
Oh I've just found the solution, I added the new function to the get_whitelist, and that help! :D

Bookmarks

Tags
only index page, random post

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Random posts on home page bogdanvelea Center area post/pages 4 Apr 10, 2011 03:33 PM
[SOLVED] How to Add Author Description to Page generated by &quot;%author-posts-link%&quot; Steve41 Post-Kicker, -Byline & -Footer 3 Dec 15, 2010 03:46 PM
Restrict posts on index to a specific category. amish_geek Center area post/pages 2 Feb 17, 2010 04:13 PM
Hiding a category from index : success but posts unreachables vil2 Excerpts, Read more, Pagination 2 Jan 24, 2010 03:41 PM
Subscribe to Posts by category or author alby RSS, Feeds & Subscribing 2 Jan 24, 2010 06:01 AM


All times are GMT -6. The time now is 01:21 PM.


Powered by vBulletin® Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.