Wordpress Themes - WP Forum at BFA
There will be no more development for Atahualpa (or any other theme), and no support. Also no new registrations. I turned off the donation system. I may turn the forum to read only if it gets abused for spam. Unfortunately I have no time for the forum or the themes. Thanks a lot to the people who helped in all these years, especially Larry and of course: Paul. Take care and stay healthy -- Flynn, Atahualpa developer, Sep 2021

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
Smile [SOLVED] How to have random posts only on index page (not category, author...)?

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



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 06:04 AM.


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