2015-07-28 3 views
0

Я создал пользовательский тип сообщения, называемый событиями. Затем я создал страницу шаблона, чтобы перечислить все события. Я пытаюсь перечислить их в петле сетки с классами «первая» и «одна треть», чтобы я мог использовать gensis, встроенный в grid-классы.Genesis Grid Классы для персонализированного шаблона типа сообщения

Однако все, что я пробовал, не ставит класс «первым» на первый элемент. Я только когда-либо размещаю «одну треть» на всех постах, а не

Я попытался использовать более удобную форму счета цикла сетки erickson http://www.billerickson.net/a-better-and-easier-grid-loop/, но это работает только на все, кроме моего настраиваемого типа сообщений. Алос попробовал другой метод, который я нашел.

Моя страница шаблона и методы, которые я пробовал, приведены ниже. Спасибо за любое направление, которое вы можете дать, поскольку я в тупике в этом пункте ниже. благодаря

ПРОБОВАЛИ И НЕ

function be_archive_post_class($classes) { 
    global $wp_query; 
    if(! $wp_query->is_main_query()) 
     return $classes; 

    if (is_page('events')){ 
     $classes[] = 'one-third'; 
     if(0 == $wp_query->current_post || 0 == $wp_query->current_post % 3) 
     $classes[] = 'first'; 
     return $classes; 
    } 
} 
add_filter('post_class', 'be_archive_post_class'); 

//I also Added the if(is_page('events')){} to the above 

ТАКЖЕ Пробовал Разновидности этого ВНУТРИ МОЕГО WHILE LOOP НА СОБЫТИЯ ШАБЛОНЕ

$c = 0;  
while (have_posts()) : the_post(); 

    if($c % 3 == 0){ 
     $style = 'one-third'; 
    } 
    else{ 
     $style = 'first'; 
    } 
    $c++; 
} 

<?php post_class($style) ?> 

СОБЫТИЯ ШАБЛОН PAGE

<?php 
/** 
* Template Name: Events Template 
* Description: Used as a CPT Archive for our Events Custom Post Type 
* 
*/ 

/** Replace the standard loop with our custom loop */ 
// Do the Custom Loop 
remove_action('genesis_loop', 'genesis_do_loop'); 
add_action('genesis_loop', 'ame_custom_loop'); 


//Comparing the end date with the timestamp so that old events don't show 
function ame_custom_loop(){ 
    $meta_quer_args = array(
     'relation' => 'AND', 
     array(
      'key' => 'event-end-date', 
      'value' => time(), 
      'compare' => '>=' 
     ) 
    ); 

    //Define Our Arguments 
    $query_args = array(
     'post_type' => 'event', 
     'posts_per_page' => $instance['number_events'], 
     'post_status' => 'publish', 
     'ignore_sticky_posts' => true, 
     'meta_key' => 'event-start-date', 
     'orderby' => 'meta_key', 
     'order' => 'ASC', 
     'meta_query' => $meta_quer_args 
    ); 

    $upcoming_events = new WP_Query($query_args); 

    while($upcoming_events->have_posts()): $upcoming_events->the_post(); 

     $event_start_date = get_post_meta(get_the_ID(), 'event-start-date', true); 
     $event_end_date = get_post_meta(get_the_ID(), 'event-end-date', true); 
     $event_street_address = get_post_meta(get_the_ID(), 'event-street-address', true); 
     $event_city = get_post_meta(get_the_ID(), 'event-city', true); 
     $event_postal_code = get_post_meta(get_the_ID(), 'event-postal-code', true); 
     $event_venue = get_post_meta(get_the_ID(), 'event-venue', true); 
     $event_start_time = get_post_meta(get_the_ID(), 'event-start-time', true); 
     $event_end_time = get_post_meta(get_the_ID(), 'event-end-time', true); ?> 


     <article id="post-<?php the_ID();?>" <?php post_class() ?> itemscope="" itemtype="http://schema.org/Event"> 
      <header class="entry-header"> 
       <p class="entry-meta"> 
        <time class="entry-time start-time" datetime="<?php echo date('F d, Y', $event_start_date);?>" itemprop="startDate"><?php echo date('F d, Y', $event_start_date); ?></time> 
        <?php 
         if($event_end_date != NULL){ ?> 
          <time class="entry-time end-time" datetime="<?php echo date('F d, Y', $event_end_date);?>" itemprop="endDate"><?php echo date('F d, Y', $event_end_date); ?></time> 
        <?php } 
        ?> 
       </p> 
       <h1 class="entry-title" itemprop="headline"><a href="<?php echo get_the_permalink(); ?>"><?php echo get_the_title() ?></a></h1> 
      </header> 
     </article> 

    <?php endwhile; 
} 
genesis(); 

ответ

0

После долгих проб и ошибок и исследований я нашел ответ здесь с небольшим изменением здесь на wordpress forum

Убедитесь, что вы размещаете внутри время цикла

$postcount++; 
$new_class = (($postcount % 3) == 1) ? "first one-third" : "one-third"; 

//Then add the actual post structure 
<article <?php post_class($new_class) ?> id="post-<?php the_ID();?>" itemscope="" itemtype="http://schema.org/Event"> 
    //Add whatever else you need in here 
</article> 

Надежда, которая может помочь кому-то.

 Смежные вопросы

  • Нет связанных вопросов^_^