fususu |
Jun 19, 2013 01:59 AM |
[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 :)
|