突出显示侧栏页面中的当前帖子

时间:2016-01-31 20:24:19

标签: php wordpress

我在博客中添加了一个侧边栏页面,现在我想在用户点击该帖子时突出显示该帖子。

如何突出显示wordpress中的当前帖子?

请给我建议。

以下是我的page.php

<?php

get_header();
?>
<div id="primary" class="content-area">
  <main id="main" class="site-main" role="main">
    <?php get_template_part('content', 'header'); ?>

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

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

            <?php
            // If the theme is set to display comments
            if (get_theme_mod('uu2014_display_comments_pages', 1)) {
                // If comments are open or we have at least one comment, load up the comment template
                if ( comments_open() || get_comments_number() ) {
                    comments_template();
                }
            } ?>

        <?php endwhile; // end of the loop. ?>

    <?php get_template_part('content', 'footer'); ?>
    </main><!-- #main -->
</div><!-- #primary -->


<?php get_sidebar(); ?>
<?php get_footer(); ?>

的sidebar.php

$uu2014_widget_default_args = array(
  'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  'after_widget'  => '</aside>',
  'before_title'  => '<h1 class="widget-title">',
  'after_title'   => '</h1>',
);
?>
<div id="secondary" class="sidebar-widget-area widget-area" role="complementary">
    <nav role="navigation" class="navigation site-navigation secondary-navigation">
        <?php wp_nav_menu( array( 'theme_location' => 'secondary' ) ); ?>
    </nav>
    <?php if (!dynamic_sidebar('home-widgets')) : ?>
        <?php the_widget( 'WP_Widget_Recent_Posts', null, $uu2014_widget_default_args ); ?>
        <?php the_widget( 'WP_Widget_Archives', null, $uu2014_widget_default_args ); ?>
        <?php the_widget( 'WP_Widget_Categories', 'hierarchical=1', $uu2014_widget_default_args ); ?>
    <?php endif; // end sidebar widget area  ?>
</div><!-- #secondary -->

1 个答案:

答案 0 :(得分:0)

最简单的方法是在包含帖子ID的链接中添加一个类。

Ramons-MacBook-Pro-3:project4 sacrams14$ npm install
npm WARN package.json project4@1.0.0 No repository field.
npm WARN package.json project4@1.0.0 No README data
npm ERR! Darwin 14.0.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"
npm ERR! node v4.2.6
npm ERR! npm  v2.14.12
npm ERR! code ENOTFOUND
npm ERR! errno ENOTFOUND
npm ERR! syscall getaddrinfo

npm ERR! network getaddrinfo ENOTFOUND registry.npmjs.org registry.npmjs.org:80
npm ERR! network This is most likely not a problem with npm itself
npm ERR! network and is related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network 
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly.  See: 'npm help config'

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/sacrams14/Dropbox/CS 142/project4/npm-debug.log

然后,您可以编写自定义CSS函数,将其放在<a href="<?php the_permalink() ?>" class="post-<?php echo get_the_ID(); ?>"> 中并挂钩functions.php。此功能仅用于回显必要的CSS以突出显示链接。

wp_head