首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将帖子的链接分配给包含该帖子的<article>?

将帖子的链接分配给包含该帖子的<article>?
EN

WordPress Development用户
提问于 2018-03-12 18:45:24
回答 1查看 39关注 0票数 0

我试图弄清楚如何才能将每个帖子的链接分配给每个包含它的项目。我想点击一下,这样我就可以转到文章中包含的页面。

下面是我正在讨论的<article>项目(在content.php文件中):

代码语言:javascript
复制
<?php
/**
 * Template part for displaying posts
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package meptheme
 */

?>
    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    <header class="entry-header">
        <?php
        if ( is_singular() ) :
            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() ) : ?>
        <div class="entry-meta">
            <?php meptheme_posted_on(); ?>
        </div><!-- .entry-meta -->
        <?php
        endif; ?>
    </header><!-- .entry-header -->

    <div class="entry-content">
        <?php
            the_content( sprintf(
                wp_kses(
                    /* translators: %s: Name of current post. Only visible to screen readers */
                    __( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'meptheme' ),
                    array(
                        'span' => array(
                            'class' => array(),
                        ),
                    )
                ),
                get_the_title()
            ) );

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

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

下面是一个例子:我在这个页面上,http://nuovomep.altervista.org/m-49,我想点击第一个<article>,并寻址到http://nuovomep.altervista.org/m-49/26341

第17行的<a>标记包含正确的链接:<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a>

EN

回答 1

WordPress Development用户

回答已采纳

发布于 2018-03-12 20:11:26

这应该对你有帮助:

代码语言:javascript
复制
<?php
    if ( !is_singular() ) :
 echo '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">';
    endif;?>

 Here is your existing <article></article> codes

<?php
    if ( !is_singular() ) :
 echo '</a>';
    endif;?>
票数 -1
EN
页面原文内容由WordPress Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://wordpress.stackexchange.com/questions/296554

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档