繁体   English   中英

如何使发布循环分为两列/ Wordpress

[英]How to make post loop in two columns / Wordpress

我一直在尝试拆分帖子。 我尝试了多种变体,但是每次我发布一个帖子或将我全部复制两次时。 我的意思是多个职位。

如果有人知道如何解决它,我将非常感谢他。

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    <?php do_action( 'esteem_before_post_content' ); ?>
    <?php
        if( has_post_thumbnail() ) {
            $image = '';
            $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'blog-large');
            $title_attribute = the_title_attribute( 'echo=0' );
            $image .= '<figure class="post-featured-image">';
            $image .= '<a href="' . get_permalink() . '" title="'.the_title_attribute( 'echo=0' ).'">';
            $image .= get_the_post_thumbnail( $post->ID, 'blog-large', array( 'title' => esc_attr( $title_attribute ), 'alt' => esc_attr( $title_attribute ) ) ).'</a>';
            $image .= '<div class="mask">
                        <div class="image-icon-wrap">
                            <a href="'.$large_image_url[0].'" class="img-icon img-search"><i class="icon-search"></i></a>
                            <a href="'.get_permalink().'" class="img-icon img-link"><i class="icon-link"></i></a>
                        </div>
                    </div>';
            $image .= '</figure>';

            echo $image;
        }
    ?>
    <div class="blog-content">
        <header class="entry-header">
            <h2 class="entry-title">
                <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute();?>"><?php the_title(); ?></a>
            </h2><!-- .entry-title -->
        </header>

        <?php esteem_entry_meta(); ?>

        <div class="entry-content clearfix">
            <?php the_excerpt(); ?>

        </div><!-- .entry-content -->
    </div>

    <?php do_action( 'esteem_after_post_content' ); ?>
</article>

发布循环

<div id="primary">
    <div id="content" class="clearfix">

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

            <?php while ( have_posts() ) : the_post(); ?>

                <?php get_template_part( 'content', get_post_format() ); ?>

            <?php endwhile; ?>

            <?php get_template_part( 'navigation', 'none' ); ?>

        <?php else : ?>

            <?php get_template_part( 'no-results', 'none' ); ?>

        <?php endif; ?>

    </div><!-- #content -->
</div><!-- #primary -->

如果有人知道如何解决它,我将非常感谢他。

由于您已经在调用post_class()函数,因此需要将替代类传递给该函数本身,并确保仅在自定义页面或选定的博客页面上执行此操作。 该代码本质上将类似于:

global $current_class;
$current_class = 'odd'; 
function alternating_post_class ( $classes ) {
    global $current_class;
    if( is_page(<PAGE_ID_HERE>) || is_home() ):
        $classes[] = $current_class;
        $current_class = ($current_class == 'odd') ? 'even' : 'odd';
    endif;
    return $classes;
}
add_filter ('post_class', 'alternating_post_class');

这应该通过给您提供奇数/偶数类来解决此问题,您可以使用它来设置两列的样式。

队友的欢呼声!!!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM