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.

Ok I've been asked to fix a problem on a website that is a bit weird. The index page (template-magazine.php) here, Has this bit of code:

<?php get_template_part('loop'); ?>

to produce a list/grid of latest news and here everything is fine, each entry is represented by a time and place and a snippet of the description of the event.

When you click a category you call the archive.php example and archive.php has the same call:

<?php get_template_part('loop'); ?>

to build the list/grid of events. But now the output is time and place as before but the snippet includes the time and date as well.

Now I should mention that the the posts displayed are a custom post type from the All-in-One Event Calendar (by Timely). The problem might be connected to that somehow but I am to much of a wordpress noob to be able to understand that.

The custom post type is added to the loop like this:

add_filter('pre_get_posts', 'query_post_type');

function query_post_type($query) {
  if(is_category() || is_home() || is_tag() && empty( $query-    >query_vars['suppress_filters'] )) {
        if ( empty($query->query_vars['post_type']) ) {
            $query->query_vars['post_type'] = array('post','ai1ec_event');
        } elseif ( 'any' == $query->query_vars['post_type'] ) {
            return;
        } else {
            $query->query_vars['post_type'] = (array)$query->query_vars['post_type'];
            $query->query_vars['post_type'][] = 'ai1ec_event';
        }
    }
}

Hope someone can point me in the right direction.

As requested here is the contents of loop.php:

<?php if ( have_posts() ) : ?>

<div class="loop">
    <div id="loop" class="<?php if ($_COOKIE['mode'] == 'grid' ) echo 'grid'; else echo 'list'; ?> clear">
    <?php
        $postedon_data = array(
            'date' => get_option('unspoken_postedon_date'),
            'category' => get_option('unspoken_postedon_cat'),
            'comment' => get_option('unspoken_postedon_comm'),
            'author' => get_option('unspoken_postedon_author')
        );
        $i = 0;
        while ( have_posts() ) : the_post();
            $i++;
    ?>
            <div id="post-<?php the_ID(); ?>" <?php post_class('clear'); ?>>
                <a href="<?php the_permalink(); ?>" class="post-thumb"><?php if ( has_post_thumbnail() ) the_post_thumbnail('general'); ?></a>
                <div class="post-meta"><?php if (function_exists('unspoken_posted_on')) unspoken_posted_on($postedon_data); ?></div>
                <h2><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
                <p><?php the_excerpt(); ?></p>
            </div>
    <?php
        if ( $i % 2 == 0 ) echo '<div class="clear"></div>';
        endwhile; // end of the loop.
    ?>
        <div class="grid-line"></div>
    </div><!-- #loop -->
</div><!-- .loop -->

<?php else : ?>

<div class="loop">
    <div id="post-0" class="post hentry error404 not-found clear">
        <h2><?php _e( 'Not found', 'unspoken' ); ?></h2>
        <p><?php _e( 'Apologies, but no results were found for the requested criteria. Perhaps searching will help find a related post.', 'unspoken' ); ?></p>
    </div><!-- #post-0 -->
</div>

<?php endif; ?>

Adding All filters I could find that did something with excerpt:

theme/unspoken/functions.php

// Custom excerpt for comments
function unspoken_excerpt($string, $limit) {
$more = '';
$words = explode(" ",$string);
if ( count($words) >= $limit) $more = '...';
$output = strip_tags( implode(" ",array_splice($words, 0, $limit)).$more );
echo $output;
}

// Custom excerpt more
function unspoken_excerpt_more($more) {
return '...';
}
add_filter('excerpt_more', 'unspoken_excerpt_more');
function unspoken_excerpt_length($length) {
return 33;
}
add_filter('excerpt_length', 'unspoken_excerpt_length');

Plugin only has an empty functions.php seems to be modelled on MVC instead. Plugin-file event-excerpt.php has this function:

<div class="timely ai1ec-excerpt">
<div class="ai1ec-time">
    <strong><?php _e( '<!--:es-->Fecha<!--:--><!--:ca-->Data<!--:--><!--:en-->Date<!--:-->:', AI1EC_PLUGIN_NAME ); ?></strong>
    <?php echo $event->get_timespan_html(); ?>
</div>
<?php if ( $location ) : ?>
    <div class="ai1ec-location">
        <strong><?php _e( '<!--:es-->Lugar<!--:--><!--:ca-->Lloc<!--:--><!--:en-->Venue<!--:-->:', AI1EC_PLUGIN_NAME ); ?></strong>
        <?php echo $location; ?>
    </div>
<?php endif; ?>
</div>

Found something that could be interesting in another plugin file called class-ai1ec-events-controller.php

/**
 * event_excerpt function
 *
 * Overrides what wp_trim_excerpt() returned if the post is an event,
 * and outputs better rich-text (but not too rich) excerpt instead.
 *
 * @return void
 **/
function event_excerpt( $text )
{
    global $ai1ec_view_helper,
           $ai1ec_events_helper;

    if ( get_post_type() != AI1EC_POST_TYPE ) {
        return $text;
    }

    $event = new Ai1ec_Event( get_the_ID() );

    ob_start();

    $this->excerpt_view( $event );

    // Re-apply any filters to the post content that normally would have been
    // applied if it weren't for our interference (below).
    echo shortcode_unautop( wpautop(
            $ai1ec_events_helper->trim_excerpt(
                apply_filters( 'the_content', $event->post->post_content )
            )
    ) );

    $page_content = ob_get_contents();
    ob_end_clean();

    return $page_content;
}

/**
 * event_excerpt_noautop function
 *
 * Conditionally apply wpautop() filter to content, only if it is not an
 * event.
 *
 * @return void
 **/
function event_excerpt_noautop( $content ) {
    if ( get_post_type() != AI1EC_POST_TYPE ) {
        return wpautop( $content );
    }
    return $content;
}

Found this in /model/class-ai1ec-event.php

/**
 * Get excerpt of post content for display in popup view
 */
public function get_post_excerpt() {
    if (
        ! isset( $this->post->post_excerpt ) ||
        empty( $this->post->post_excerpt )
    ) {
        $content = strip_tags(
            strip_shortcodes(
                apply_filters( 'the_content', $this->post->post_content )
            )
        );
        $content = preg_replace( '/\s+/', ' ', $content );
        $words = explode( ' ', $content );
        if ( count( $words ) > 25 ) {
            $this->post->post_excerpt = implode(
                ' ',
                array_slice( $words, 0, 25 )
            ) . ' [...]';
        } else {
            $this->post->post_excerpt = $content;
        }
    }
    return $this->post->post_excerpt;
}

And that is all I could find on excerpts, hope it helps.

share|improve this question
    
That filter is poorly written, it is not passing any data back to the filter, it should be returning $query at the end of the function and inside the elseif statement. –  t31os Apr 24 '13 at 10:49
    
what is the code in loop.php? also, check the css for any template related styles. –  Michael Apr 24 '13 at 11:51
    
pre_get_posts is an action. It doesn't need to return anything. It is being misused as a filter. –  s_ha_dum Apr 24 '13 at 13:58
    
The missing piece of information appears to me to be the contents of loop.php. Would you add that please? –  s_ha_dum Apr 24 '13 at 14:00
    
Regarding the css could that really make such a difference? anyways will look into it. (BTW. Theme is Unspoken, Oh and the loop.php is untouched) –  Mikkel Gadegaard Apr 24 '13 at 14:16

1 Answer 1

The only thing date related in that code is $postedon_data. If these are the files being used as you say then there are a few possibilities.

  1. Those unspoken_postedon_* values are set in one case and not set in another.
  2. The unspoken_posted_on function is defined in one case and not another.
  3. There is something about the unspoken_posted_on function that filters what content it displays based on template or other value.

Those are the only options that come to mind. I suspect the last one.

If you can't work out which it is, var_dump($postedon_data) for both cases and edit the output into the question, and post the content of the unspoken_posted_on` function.

share|improve this answer
    
But isn't it the the_excerpt() method that returns something different? I might be a little slow here and I might have formulated my question badly. My problem is that in one case the_excerpt() returns "miniSCREEN es .... etc" and in the other case it outputs "View Map Fecha: 24 mayo, 2013 @ 18:00 – 25 mayo, 2013 @ 20:00 Lugar: LOOP. Hotel Catalonia Ramblas , Carrer de Pelai, 28,08001 Barcelona, España miniSCREEN es .... etc" –  Mikkel Gadegaard Apr 24 '13 at 14:40
    
Actually, I don't know. All I can tell from the code is that the only date related items are the ones I mentioned. the_excerpt shouldn't be echoing different content. There could be a filter on the_excerpt but it is not in the code you posted. It would be worth looking for one though. Are the dates you see above or below the call to the_excerpt. –  s_ha_dum Apr 24 '13 at 14:43
    
In the first example some info is skipped/ignored (as it should) –  Mikkel Gadegaard Apr 24 '13 at 14:44
    
The well formatted ones are above. And in the unwanted scenario they are repeated. –  Mikkel Gadegaard Apr 24 '13 at 14:45
    
It must be a filter on the_excerpt() then because I am positive that the date comes from that call and not the unspoken_posted_on function. –  Mikkel Gadegaard Apr 24 '13 at 14:50

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.