我注意到有很多关于从Wordpress中的特色图片中删除链接的问题。经过几天的搜索和使用试用版后,这是另一个我没有找到答案的答案。删除和修改代码时出错。
我想删除每次通过“特色图片”插入图片时自动生成的链接。正如您猜测的那样,这是通过投资组合(而不是页面或帖子)完成的。
我怀疑解决方案位于下面的代码中,该代码是从functions.php中提取的:
// Get Featured Image + Link
function get_featured_image( $img_size, $fallback ) {
global $post;
$post_hide_featured_single = get_post_meta($post->ID, 'post_hide_featured_single', true);
if ( is_single() && $post_hide_featured_single ) {
return false;
}
if ( has_post_thumbnail() ) {
$featured_image_link_to = get_post_meta($post->ID, 'featured_image_link_to', true);
$featured_image_link_to_url = get_post_meta($post->ID, 'featured_image_link_to_url', true);
if ( $featured_image_link_to_url ) {
$featured_image_link = $featured_image_link_to_url;
}else{
if ( $featured_image_link_to == 'post' ) {
$featured_image_link = get_permalink();
}else if ( $featured_image_link_to == 'image' || !$featured_image_link_to ) {
$featured_image_link = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
$featured_image_link = $featured_image_link[0];
}
} // end if url set
$featured_image = get_the_post_thumbnail($post->ID, $img_size, array( 'class' => '' ));
}else{ // no thumbnail set
$featured_image_link = get_permalink();
$featured_image = $fallback;
} // end if has featured image
if ( has_post_thumbnail() ) {
return "<div class='post-thumbnail'><a href='" . $featured_image_link . "'>" . $featured_image . "</a></div>";
}
我试过删除最后一行,但无济于事。我想也许是get_permalink()的事情,但我只熟悉html和css。
非常赞赏任何有关其他资源的建议或指示。
非常感谢! 戴夫
附加信息:
用于在single-portfolio.php中显示图像的代码如下:
<div class="grid_8"id="aside">
<?php
if ( $portfolio_layout == 'attachment_list' || ! $portfolio_layout ) {
$gallery_options = array( 'display' => 'list', 'source' => 'attachment' );
echo attachment_gallery( $gallery_options );
}else if ($portfolio_layout == 'attachment_slider' ){
$gallery_options = array( 'display' => 'slider', 'source' => 'attachment' );
echo attachment_gallery( $gallery_options );
}else if ( $portfolio_layout == 'video' ) {
// print_r_pre( get_post_custom() );
$embed = get_post_meta( $post->ID, 'portfolio_video_src_embed', true );
// If video embed source filled in, use it above all others
if ( $embed ) {
echo do_shortcode( $embed );
}
}else{
echo '<!-- template not found -->';
}
?>
<?php wp_reset_query(); comments_template( '', true ); ?>
</div><!--//grid_8-->
更多其他信息:
以下是attachment_gallery的代码:
// Gallery Function (list, gallery, slider, etc...)
function attachment_gallery( $options ) {
global $post, $wp_query;
$output = "";
$original_wp_query = $wp_query;
$wp_query = null;
// Default options, overridden by extract() below if set
$source = 'attachment';
$display = 'list';
$media_size = 'grid_8';
$slide_effect = '';
$slide_delay = '';
$slide_speed = '';
$slide_nav = '';
$slide_nav_nextprev = '';
// Extract options from array to variables
extract( $options );
$args = array(
'post_parent' => $post->ID,
'post_type' => $source,
'post_mime_type' => 'image',
'post_status' => 'inherit',
'order' => 'ASC',
'orderby' => 'menu_order',
'posts_per_page' => -1
);
// Run the new query
$wp_query = new WP_Query( $args );
// Slider wrap
if( $display == 'slider' ) { $output .= "<div class='slides_container'>"; }
$slide_counter = 0;
$output .= "<ul class='stripped thumbnail-list clearfix'>";
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
if ( $slide_counter > 0 && $display == 'slider' ) { $output .= "<li class='hidden'>"; }else{ $output .= "<li>"; }
$output .= "<div class='content'>";
if ( $source == 'attachment' ) {
$post_thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
$output .= "<div class='post-thumbnail'><a href='" . $post_thumbnail_src[0] . "'>";
$output .= wp_get_attachment_link($post->ID, $media_size, false, false);
$output .= "</a></div>";
}
if ( $source == 'slider' || $source == 'post' || $source == 'portfolio' ) {
$output .= get_featured_image( $media_size, '' );
}
$output .= "</div><!--//content-->";