获取已点击 post 的特色图片 url
Get the featured image url of clicked post
如何在模式中显示 post 的特色图片及其内容。
在一些类似问题的在线线程的帮助下,我尝试了这个:
<?php
if ( has_post_thumbnail()) {
echo '<a href="' . get_permalink($post->ID) . '" >';
the_post_thumbnail('my_feature_image', array( 'class' => "someName" ));
echo '</a>';
}
?>
不幸的是 returns 所有 post 的特色图片都是一样的。
在找到模态的同一个 header.php
上,有以下内容(在模态 div 上方):
//on the homepage... check for the post URL...
//do we have a custom permalink incoming....
$perma = false; if (isset($wp_query->query_vars['phpost_slug'])) #WHFIX 24/03/2015:
$perma = $wp_query->query_vars['phpost_slug'];
if($perma){
//we don't want to return a 404
$wp_query->set( 'is_404', false );
$phid = get_page_by_path($perma, OBJECT, 'post');
$postvote = get_post_meta($phid->ID, 'epicredvote' ,true);
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id( $phid->ID ), 'single-post-thumbnail' );
$pluginfeat = get_post_meta($phid->ID,'phog',true);
$desc = get_post($phid->ID)->post_content;
link 到站点:https://goo.gl/30a3QQ [单击 post 的行打开模式。]
更新
我试过像这样删除锚标签和 类 但它仍然不起作用:
<?php
if ( has_post_thumbnail()) {
the_post_thumbnail();
}
?>
您要更改的元素只是要填充 onclick 处理程序的 html 线框,问题是它不包含原始图像,因此您需要添加该功能。这样的东西应该可以工作(添加到您的页脚)
var eventTargets=document.querySelectorAll('.hunt-row');
[].forEach.call(eventTargets, function(t){
t.addEventListener('click', function(){
console.log('clicked');
var img= this.querySelector('img').src;
//bind new src to modal thumb, this is not ideal as there is only a class rather than a id...
document.querySelector('.modal-thumb').src= img;
}, false);
});
当然,我不确定它与其他点击处理程序一起使用时效果如何,您可能需要删除默认设置并编写自己的点击处理程序来填充模型框。
如何在模式中显示 post 的特色图片及其内容。
在一些类似问题的在线线程的帮助下,我尝试了这个:
<?php
if ( has_post_thumbnail()) {
echo '<a href="' . get_permalink($post->ID) . '" >';
the_post_thumbnail('my_feature_image', array( 'class' => "someName" ));
echo '</a>';
}
?>
不幸的是 returns 所有 post 的特色图片都是一样的。
在找到模态的同一个 header.php
上,有以下内容(在模态 div 上方):
//on the homepage... check for the post URL...
//do we have a custom permalink incoming....
$perma = false; if (isset($wp_query->query_vars['phpost_slug'])) #WHFIX 24/03/2015:
$perma = $wp_query->query_vars['phpost_slug'];
if($perma){
//we don't want to return a 404
$wp_query->set( 'is_404', false );
$phid = get_page_by_path($perma, OBJECT, 'post');
$postvote = get_post_meta($phid->ID, 'epicredvote' ,true);
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id( $phid->ID ), 'single-post-thumbnail' );
$pluginfeat = get_post_meta($phid->ID,'phog',true);
$desc = get_post($phid->ID)->post_content;
link 到站点:https://goo.gl/30a3QQ [单击 post 的行打开模式。]
更新
我试过像这样删除锚标签和 类 但它仍然不起作用:
<?php
if ( has_post_thumbnail()) {
the_post_thumbnail();
}
?>
您要更改的元素只是要填充 onclick 处理程序的 html 线框,问题是它不包含原始图像,因此您需要添加该功能。这样的东西应该可以工作(添加到您的页脚)
var eventTargets=document.querySelectorAll('.hunt-row');
[].forEach.call(eventTargets, function(t){
t.addEventListener('click', function(){
console.log('clicked');
var img= this.querySelector('img').src;
//bind new src to modal thumb, this is not ideal as there is only a class rather than a id...
document.querySelector('.modal-thumb').src= img;
}, false);
});
当然,我不确定它与其他点击处理程序一起使用时效果如何,您可能需要删除默认设置并编写自己的点击处理程序来填充模型框。