如何为特定的wordpress侧边栏小部件设置样式

时间:2017-11-14 11:35:12

标签: wordpress-theming

当我在我的网站上打开帖子时,我可以看到侧边栏小部件。但由于该网站是双语的,其中一些应该是正确对齐的,而另一些则是左对齐的。

这可能吗?如果我知道哪个函数正在生成侧边栏HTML的内容,也许我可以实现这一点,但我不知道该函数在哪里,如果它存在。

1 个答案:

答案 0 :(得分:0)

嗯......有点工作了。

我对文件进行了以下更改: WP-包括\部件\类-WP-插件-最近-posts.php

它有以下代码:

<ul>
        <?php while ( $r->have_posts() ) : $r->the_post(); ?>
            <li>
                <a href="<?php the_permalink(); ?>"><?php get_the_title() ? the_title() : the_ID(); ?></a>
            <?php if ( $show_date ) : ?>
                <span class="post-date"><?php echo get_the_date(); ?></span>
            <?php endif; ?>
            </li>
        <?php endwhile; ?>
        </ul>
然后我将其改为:

<ul>
        <?php while ( $r->have_posts() ) : $r->the_post(); ?>

            <?php
            if (strpos(get_the_title(), 'a') !== false) {
                echo '<li class="engwidget">';
            }else{
                echo '<li class="localwidget">';
            } 
            ?>

                <a href="<?php the_permalink(); ?>"><?php get_the_title() ? the_title() : the_ID(); ?></a>
            <?php if ( $show_date ) : ?>
                <span class="post-date"><?php echo get_the_date(); ?></span>
            <?php endif; ?>
            </li>
        <?php endwhile; ?>
        </ul>

我已经实现了我想要的但不知道这是否是一种正确的方法。

相关问题