我正在为我的博客开发一个wordpress主题,我遇到了一些困难。
当我发布一个新帖子时,该帖子的第一张图片就会显示在主页上。单击图像时,它将链接到图像文件并显示完整大小。我想让它自动链接到它来自的帖子。我知道你可以在上传时或在编辑器中选择图片的链接。我想让图片自动链接到它们的原始帖子,因为我有其他人在我的博客上写东西,我不希望他们每次都这样做。
据我所知,在这种情况下,content.php文件控制post格式。这是我的主题中的文件。或者可以使用函数?
<?php
/**
* The default template for displaying content single/search/archive
*
* @package test
* @since test 0.1.0
*/
?>
<!-- START: content.php -->
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<?php if ( is_single() ) : ?>
<h1 class="entry-title"><?php the_title(); ?></h1>
<?php else : ?>
<?php the_post_thumbnail(); ?>
<h1 class="entry-title">
<a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( sprintf( __( 'Permalink to %s', 'test' ), the_title_attribute( 'echo=0' ) ) ); ?>" rel="bookmark"><?php the_title(); ?></a>
</h1>
<?php endif; // is_single() ?>
</header><!-- .entry-header -->
<?php if ( 'post' == get_post_type() ) : ?>
<div class="entry-meta">
<?php posted_on(); ?>
<?php if ( is_sticky() && is_home() && ! is_paged() ) : ?>
<span class="label radius secondary"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'test' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php _ex( 'Featured', 'Post format title', 'test' ); ?></a></span>
<?php endif; ?>
</div><!-- .entry-meta -->
<?php endif; ?>
<?php if ( is_search() ) : // Only display Excerpts for Search ?>
<div class="entry-summary">
<?php the_excerpt(); ?>
</div><!-- .entry-summary -->
<?php else : ?>
<div class="entry-content">
<?php the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'test' ) ); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'test' ) . '</span>', 'after' => '</div>' ) ); ?>
</div><!-- .entry-content -->
<?php endif; ?>
<footer class="entry-meta">
<?php if ( 'post' == get_post_type() ) : ?>
<?php get_template_part('entry-meta', get_post_format() ); ?>
<?php endif; ?>
</footer><!-- #entry-meta -->
</article><!-- #post-<?php the_ID(); ?> -->
<!-- END: content.php -->发布于 2013-12-27 09:14:14
https://codex.wordpress.org/Function_Reference/the_post_thumbnail示例1.要将帖子缩略图链接到特定循环中的帖子固定链接,请在主题的模板文件中使用以下内容:
<?php if ( has_post_thumbnail()) : ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
<?php the_post_thumbnail(); ?>
</a>
<?php endif; ?>https://stackoverflow.com/questions/20792879
复制相似问题