我有一个Wordpress儿童主题网站http://mrme.me/utahcountyhiking, 我正在尝试获取它,这样当你点击特色图片时,它就会转到相关的帖子。现在,它会转到媒体页面,查看特色图片,而不是帖子。
我试过的
我知道了如何让子主题加载一些JavaScript,但JS是在PHP向页面添加内容之前运行的,所以我无法使用JS进行更改。
我试着添加这些PHP functions “我的孩子”主题函数。php文件,但这并没有改变任何东西。
编辑:使用Wordpress功能设置特色图像wp_get_attachment_link() 返回包含链接到图像附件页的图像的html。
设置特征图像的代码为
<?php
    if(get_post_thumbnail_id(get_the_ID())) {
        $besty_featured_image = wp_get_attachment_link( get_post_thumbnail_id(get_the_ID()), \'besty-thumbnail\', true ); 
        echo $besty_featured_image;
    }
?>            
    <a href="<?php echo esc_url( get_permalink() ); ?>" class="blog-title"><?php the_title();?></a>
 
                    最合适的回答,由SO网友:Brad Dalton 整理而成
                    主题定制是离题的,但默认主题是例外的,所以让我们看一个例子,看看它是如何在2015年完成的。
if ( ! function_exists( \'twentyfifteen_post_thumbnail\' ) ) :
function twentyfifteen_post_thumbnail() {
    if ( post_password_required() || is_attachment() || ! has_post_thumbnail() ) {
        return;
    }
    if ( is_singular() ) :
    ?>
    <div class="post-thumbnail">
        <?php the_post_thumbnail(); ?>
    </div><!-- .post-thumbnail -->
    <?php else : ?>
    <a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true">
        <?php
            the_post_thumbnail( \'post-thumbnail\', array( \'alt\' => get_the_title() ) );
        ?>
    </a>
    <?php endif; // End is_singular()
}
endif;
 您可以看到此行包括
the_permalink 所有的一切都包裹在
<a> 将帖子缩略图链接到帖子永久链接的标记。
<a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true">
 
                     
                
                
                SO网友:wp-overwatch.com
                根据Brad的答案,我可以通过在主题索引中使用以下代码来修复它。html文件
<div class="post-box article">
  <a href="<?php echo esc_url( get_permalink() ); ?>" class="blog-title">
    <?php the_post_thumbnail( \'post-thumbnail\', array( \'alt\' => get_the_title() ) ); ?>
    <div class="myTitleClass"><?php echo the_title(); ?></div>
  </a>
</div>
 我确实意识到,使用子主题而不是直接编辑文件会更好,但现在这已经足够好了。