【问题标题】:how to add <hr> on wordpress blogs view section如何在 wordpress 博客视图部分添加 <hr>
【发布时间】:2017-08-16 15:17:01
【问题描述】:

大家好,我是 WP 开发新手,这是我的客户站点:bit.do/dFQtv 我需要在下面的每个博客摘录下添加 hr 行阅读更多部分,如果我插入下面的行,该怎么做更多按钮也会显示在单个博客文章页面中

这是编码:(template-parts/content.php)

 <?php
/**
 * Template part for displaying posts
 *
 * @link https://codex.wordpress.org/Template_Hierarchy
 *
 *
 */

?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    <header class="entry-header">
        <?php
        if ( is_single() ) :
            the_title( '<h1 class="entry-title">', '</h1>' );
        else :
            the_title( '<h2 class="entry-title"><a href="' . esc_url( get_permalink() ) . '"  rel="bookmark" >', '</a></h2>' );
        endif;

        if ( 'post' === get_post_type() ) :  ?>
        <h4 class="meta text-muted">
            <?php blog_posted_on(); ?>
        </h4><!-- .entry-meta -->
        <?php
        endif; ?>

        <!-- AddThis Button BEGIN -->
    <div class="addthis_inline_share_toolbox_mzc3" style="margin-bottom:20px;" data-title="<?php the_title() ?>" data-url="<?php the_permalink(); ?>" </div>
        <!-- AddThis Button END -->

    </header><!-- .entry-header -->

    <div class="entry-content">


        <?php
                     the_content( sprintf (
                /* translators: %s: Name of current post. */
                wp_kses(__( 'Read more', 'blog' ), array( 'span' => array( 'class' => 
array() ) ) ),

                the_title( '<span class="screen-reader-text">"', '"</span>', false )
            ) );


               wp_link_pages( array(
                            'before' => '<div class= "page-links">'. esc_html__('Pages:', 'blog'
),

                           'after'  => '</div>',
            ) );
        ?>

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

    <footer class="entry-footer">
        <?php blog_entry_footer(); ?>
    </footer><!-- .entry-footer -->
</article><!-- #post-## -->

(模板部分/内容页面.php)

<?php
/**
 * Template part for displaying page content in page.php
 *
 * @link https://codex.wordpress.org/Template_Hierarchy
 *
 *
 */

?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    <header class="entry-header">
        <?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
    </header><!-- .entry-header -->

    <div class="entry-content"><hr>
        <?php
            the_content();


            wp_link_pages(array(
                'before' => '<div class="page-links">' . esc_html__('Pages:','blog'),
                'after'  => '</div>',
            ) );
        ?>
    </div><!-- .entry-content -->


    <?php if ( get_edit_post_link() ) : ?>
        <footer class="entry-footer">
            <?php
                edit_post_link(
                    sprintf(
                        /* translators: %s: Name of current post */
                        esc_html__( 'Edit %s', 'blog' ),
                        the_title( '<span class="screen-reader-text">"', '"</span>', false )
                    ),
                    '<span class="edit-link">',
                    '</span>'
                );
            ?>
<hr>
        </footer><!-- .entry-footer -->
    <?php endif; ?>
</article><!-- #post-## -->

【问题讨论】:

  • 你试过的显示代码
  • @Nawin 数组('类' => 数组()))),
  • 尝试根据您的问题编辑您的代码,而不是在评论中...
  • 如果我在 (template-parts/content.php) 中提到
    它会在单个帖子视图中显示
  • 你试过你的template-parts/archives.php
  • 标签: php wordpress wordpress-theming


    【解决方案1】:

    根据您的主题,您将&lt;hr&gt; 标签的最后一行添加到content.php 内的template-parts 文件夹中。 像这样:

    <footer class="entry-footer">
            <?php bfablog_entry_footer(); ?>
        </footer><!-- .entry-footer -->
    </article><!-- #post-<?php the_ID(); ?> --><hr>
    

    仔细检查您编辑的文件是否正确...我试过了,它正在工作

    【讨论】:

    • 嗨@Nawin 它的工作,但它也显示在单个帖子内容页面中,请参阅此帖子网址:bit.ly/2uHVIFN,我只想在博客存档页面中显示:bit.do /dFQtv
    • 感谢@Nawin 我从comment.php 中删除了单个帖子的hr,现在我认为它工作正常,再次感谢兄弟
    【解决方案2】:

    在关闭文章标签后添加hr标签,也可以为它编写CSS来改变它的宽度和颜色。

    <?php
    /**
     * Template part for displaying page content in page.php
     *
     * @link https://codex.wordpress.org/Template_Hierarchy
     *
     *
     */
    
    ?>
    
    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
        <header class="entry-header">
            <?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
        </header><!-- .entry-header -->
    
        <div class="entry-content"><hr>
            <?php
                the_content();
    
    
                wp_link_pages(array(
                    'before' => '<div class="page-links">' . esc_html__('Pages:','bfablog'),
                    'after'  => '</div>',
                ) );
            ?>
        </div><!-- .entry-content -->
    
    
        <?php if ( get_edit_post_link() ) : ?>
            <footer class="entry-footer">
                <?php
                    edit_post_link(
                        sprintf(
                            /* translators: %s: Name of current post */
                            esc_html__( 'Edit %s', 'bfablog' ),
                            the_title( '<span class="screen-reader-text">"', '"</span>', false )
                        ),
                        '<span class="edit-link">',
                        '</span>'
                    );
                ?>
    <hr>
            </footer><!-- .entry-footer -->
        <?php endif; ?>
    </article><!-- #post-## -->
    <hr class="abc" />

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-02
      • 1970-01-01
      相关资源
      最近更新 更多