我试图弄清楚如何才能将每个帖子的链接分配给每个包含它的项目。我想点击一下,这样我就可以转到文章中包含的页面。
下面是我正在讨论的<article>项目(在content.php文件中):
<?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>
发布于 2018-03-12 20:11:26
这应该对你有帮助:
<?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;?>https://wordpress.stackexchange.com/questions/296554
复制相似问题