Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How guys , i my archive themplate i have 3 tipe of themes: -poster -complex -simple

How can i display a certain number of post for arhive themes:

Ex: for my poster i want to display 24 posts(only the poster and title), for complex i want to display 12 posts(full with excerpt..), for simple i eant to display 30 ( only titles)

I have tree themes for the archive.php

Archive.php

<div class="breadcrumbs">
    <?php if(function_exists('bcn_display'))
    {
        bcn_display();
    }?>
</div>

<div class="art-content-film">
<div class="box-lay"> 
                <a href="?afisare=complex" class="grid" title="Grid"><span></span></a>  
                <a href="?afisare=poster" class="poster" title="Poster"><span></span></a> 
                <a href="?afisare=simple" class="list" title="List"><span></span></a> 
</div> 
<?php
$view = 'poster';
$mode = stripslashes( $_GET["afisare"] );
$modes = array('complex', 'simple', 'poster');
if(in_array($mode, $modes)) $view = $mode;
get_template_part('persoane', $view);
?>
</div>

<div class="art-sidebar1"> 
<?php include (TEMPLATEPATH . '/sidebar/actors.php'); ?>
<?php include (TEMPLATEPATH . '/publicitate/ad300.php'); ?>
</div>

persoane-poster.php

<div class="art-Post">
    <div class="art-Post-tl"></div>
    <div class="art-Post-tr"></div>
    <div class="art-Post-bl"></div>
    <div class="art-Post-br"></div>
    <div class="art-Post-tc"></div>
    <div class="art-Post-bc"></div>
    <div class="art-Post-cl"></div>
    <div class="art-Post-cr"></div>
    <div class="art-Post-cc"></div>
    <div class="art-Post-body">
<?php is_tag(); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>

<div class="bposter">
<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__('Film %s'), the_title_attribute('echo=0')); ?>">
<img src="/scripts/timthumb.php?src=<?php the_field('img_actor'); ?>&h=120&w=90&zc=1" alt="" title="<?php the_title(); ?>" /></a>
<div class="bpt"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'kubrick'), the_title_attribute('echo=0')); ?>">
<?php the_title(); ?>
</a></div>
</div>
<?php endwhile; ?>
<div class="cleared"></div>

</div>
</div>

<div class="nav">
<?php if(function_exists('wp_paginate')) {wp_paginate();} ?>
</div>
<?php if ($prev_link || $next_link): ?>

<?php endif; ?>

<?php else : ?>
<div class="art-Post">
    <div class="art-Post-tl"></div>
    <div class="art-Post-tr"></div>
    <div class="art-Post-bl"></div>
    <div class="art-Post-br"></div>
    <div class="art-Post-tc"></div>
    <div class="art-Post-bc"></div>
    <div class="art-Post-cl"></div>
    <div class="art-Post-cr"></div>
    <div class="art-Post-cc"></div>
    <div class="art-Post-body">
<div class="art-Post-inner art-article">

<div class="art-PostContent">

<?php
    if ( is_category() ) { // If this is a category archive
        printf("<h2 class='center'>".__("Sorry, but there aren't any posts in the %s category yet.", "kubrick").'</h2>', single_cat_title('',false));
    } else if ( is_date() ) { // If this is a date archive
        echo('<h2>'.__("Sorry, but there aren't any posts with this date.", "kubrick").'</h2>');
    } else if ( is_author() ) { // If this is a category archive
        $userdata = get_userdatabylogin(get_query_var('author_name'));
        printf("<h2 class='center'>".__("Sorry, but there aren't any posts by %s yet.", "kubrick")."</h2>", $userdata->display_name);
    } else {
        echo("<h2 class='center'>".__('No posts found.', 'kubrick').'</h2>');
    }
    if(function_exists('get_search_form')) get_search_form();
?>

</div>
<div class="cleared"></div>


</div>

        <div class="cleared"></div>
    </div>
</div>

<?php endif; ?>
share|improve this question
1  
Please try to rewrite this question. It is confusing and it is not clear what you are asking. –  s_ha_dum Jan 1 '13 at 23:00
    
do you understand want i want? s_ha_dum ? –  Batman Jan 1 '13 at 23:06
    
What is "poster", "complex", and "simple"? Are these categories? Custom meta fields? How are you determining which to use? –  s_ha_dum Jan 1 '13 at 23:10
    
no, there are themes, i use 3 themes to display a archive page persoane-poster.php , persoane-simple.php and persoane-complex.php ... in the admin of my site in setting is set to display 10 post... i want to be able to display for each one a number of post i want...somting like this tvpedia.org/lista-seriale/seriale-noi-2012 –  Batman Jan 1 '13 at 23:16
    
You are actually toggling Themes somehow? Or do you meant Template? Either way, how does WordPress, or your code, know which to display? –  s_ha_dum Jan 1 '13 at 23:21
show 1 more comment

1 Answer

up vote 0 down vote accepted

Ok. You are toggling your display according to a $_GET parameter that you have added to the URL-- this switch in your archive.php

$view = 'poster';
$mode = stripslashes( $_GET["afisare"] );
$modes = array('complex', 'simple', 'poster');
if(in_array($mode, $modes)) $view = $mode;
get_template_part('persoane', $view);

You can alter how many posts will display but that is much too late to do it.

Untested, but I would try a hook on pre_get_posts.

function toggle_modes($query) {
  global $_GET;
  if (isset($_GET["afisare"])) {
    $modes = array(
      'complex' => 12, 
      'simple' => 30, 
      'poster' => 24
    );
    if (isset($modes[$_GET["afisare"]])) {
      $query->set('posts_per_page',$modes[$_GET["afisare"]]);
    }
  }
}
add_action('pre_get_posts','toggle_modes');

Your URL parameters have to be in every request sent to this page or the pagination will get out of sync.

That is the simplest way to go from where you are to where you want to be. It may well not be the best way. You can think about something like: Passing and retrieving query vars in wordpress

share|improve this answer
    
thanks it work's –  Batman Jan 3 '13 at 23:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.