简体   繁体   English

在WordPress中使用the_post_thumbnail的问题

[英]Issues using the_post_thumbnail in wordpress

I'm teaching myself Wordpress, and my current goal is to display 4 thumbnails of images posted in a particular category. 我正在自学Wordpress,目前的目标是显示4个分类为特定类别的图像的缩略图。

I've already got the posts being pulled in by category, however I cannot pull ONLY the images. 我已经按类别列出了帖子,但是我不能仅提取图像。 It's either the images and post text, or none at all. 要么是图片,要么是文字,或者根本没有。

My code is posted here: http://pastebin.com/NZ7fyyPA 我的代码发布在这里: http : //pastebin.com/NZ7fyyPA

I've tried simply replacing 我试过简单地替换

<?php the_content(); ?>

with: 与:

<?php the_post_thumbnail(); ?>

but that didn't work at all. 但这根本没有用。 Nothing came back at all! 什么都没回来!

I've even tried simply removing: 我什至尝试简单地删除:

<?php the_content(); ?>

and same as above! 和上面一样! I was thinking that because I have 我当时在想,因为我有

<div class="entry-thumbnail"> <?php the_post_thumbnail(); ?> </div>

That would pull the thumbnail in only, so I thought removing the content would help but nope! 那只会拉入缩略图,所以我认为删除内容会有所帮助,但是不行!

I've read through the Codex here: http://codex.wordpress.org/Function_Reference/the_post_thumbnail 我在这里阅读了食典: http : //codex.wordpress.org/Function_Reference/the_post_thumbnail

and the only question I have from that, is that immediately the Codex says: 我唯一的问题是,食典委立即说:

"Use get_the_post_thumbnail($id, $size, $attr ) instead to get the featured image for any post." “使用get_the_post_thumbnail($ id,$ size,$ attr)来获取任何帖子的特色图片。”

Which I don't think I'm doing, because I haven't setup anything related to a 'featured image' in my theme...or is what I'm trying to do considered using a featured image? 我不认为我在做什么,因为我尚未在主题中设置任​​何与“特色图片”相关的内容...还是我正在尝试使用特色图片考虑的事情? I'm only uploading images and posting them inside of the blog posts. 我只是上传图像并将其发布在博客文章中。

Sorry for the long write up, I'm sure it's something simple! 很抱歉写了很长时间,我确定这很简单!

Thanks! 谢谢!

One more thing you can set a featured image from admin and call that image with this code the_post_thumbnail( $size, $attr ); 您还可以通过admin设置特色图片,并使用此代码the_post_thumbnail( $size, $attr );调用该图片the_post_thumbnail( $size, $attr ); and when you want to show anything from content part then you can call with this code simply. 当您想显示内容部分中的任何内容时,您可以简单地使用此代码进行调用。 the_content(); you can also use excerpt for this as the_excerpt(); 您也可以使用摘录作为the_excerpt();

Thanks 谢谢

This is a bit of a hack; 这有点骇人听闻; however, it works. 但是,它有效。

While viewing your Wordpress website, use the browsers developer tools to target the 'post text'. 在查看您的Wordpress网站时,请使用浏览器开发人员工具来定位“发布文字”。 You'll be able to see the id that is associated with that data-set. 您将能够看到与该数据集关联的id

Then, in your CSS. 然后,在您的CSS中。 Target that id and use display:none; 定位该id并使用display:none;

Example: 例:

#posttext {
    display:none;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用the_post_thumbnail()图像引导4张卡片可以通过wordpress拉伸以适合自己? - Bootstrap 4 cards with the_post_thumbnail() images Stretch to fit using wordpress? Wordpress:使用the_post_thumbnail()获取自定义字段图像 - Wordpress: Using the_post_thumbnail() for custom field image 在Wordpress中使用the_post_thumbnail()时,特色图片的位置不正确 - Incorrect positioning of the featured image when using the_post_thumbnail() in Wordpress 如何在wordpress上修改the_post_thumbnail函数? - How to modify the the_post_thumbnail function on wordpress? WordPress循环中的the_post_thumbnail无法正常工作 - the_post_thumbnail in WordPress Loop wont work 调整the_post_thumbnail的大小以正确拉伸,wordpress - resize the_post_thumbnail to stretch properly, wordpress wordpress中the_post_thumbnail和get_the_post_thumbnail之间的区别 - Difference between the_post_thumbnail and get_the_post_thumbnail in wordpress the_post_thumbnail(); 根据 WordPress 中的类别调用帖子时不起作用 - the_post_thumbnail(); not working when calling post based on category in WordPress 在我自己的 wordpress 主题中添加 the_post_thumbnail 作为 CSS 背景 - adding the_post_thumbnail as CSS Background, in my own wordpress theme 在wordpress主题中添加the_post_thumbnail作为CSS背景 - add the_post_thumbnail as CSS Background, in wordpress theme
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM