wp 附件页面不显示媒体 [英] wp attachment page not displaying media

查看:37
本文介绍了wp 附件页面不显示媒体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建我的第一个 Wordpress 主题.我在处理媒体附件时遇到问题.当我上传图像并将其插入帖子时,它会显示图像.如果我将它链接到媒体文件",那么在单击时它也会将我带到该文件.但是如果我尝试链接到附件页面",它不会显示图像.我没有使用自定义的attachment.php",而是只使用默认的single.php".下面是 single.php 的代码:

 <?php if (have_posts()) : while (have_posts()) : the_post();?><div class="post" id="post-<?php the_ID(); ?>"><div><h2><?php the_title();?></h2><?php 包含 (TEMPLATEPATH .'/inc/meta.php');?><div class="entry"><?php the_content();?><?php wp_link_pages(array('before' => 'Pages: ', 'next_or_number' => 'number'));?>

<?php edit_post_link('编辑此条目.', '<p>', '</p>');?>

<?php//comments_template();?><?php endwhile;万一;?>

<!--main-content Ends-->

解决方案

@Zeeshan

您的 single.php 文档似乎没有正确的 PHP 代码来输出附件.尝试在循环中添加以下代码,无论您希望附件内容出现在何处:

id)) : $att_image = wp_get_attachment_image_src($post->id, "full");?><p class="attachment"><a class="show_image" href="<?php echo wp_get_attachment_url($post->id); ?>"title="<?php echo get_the_title(); ?>"><img class="img-responsive attachment-medium" src="<?php echo $att_image[0]; ?>"height="<?php echo $att_image[2];?>"width="<?php echo $att_image[1];?>"alt="<?php echo get_the_title(); ?>"></a></p><?php 其他:?><a href="<?php echo wp_get_attachment_url($post->ID) ?>"title="<?php echo wp_specialchars( get_the_title($post->ID), 1 ) ?>"><?php echo basename($post->guid) ?></a><?php endif;?>

此代码适用于最新的 3.x CORE,但也有旧版本的回退.

如果提供,the_content() 函数输出媒体描述.

附件页面的范围从简单的attachment.php 文件到几乎十几个其他模板文件.

http://codex.wordpress.org/Template_Hierarchy#Attachment_display

附件显示

用于呈现单个附件(附件帖子类型)页面的模板文件.

  1. MIME_type.php - 它可以是任何 MIME 类型(image.php、video.php、应用程序.php).对于文本/纯文本,按顺序:

    1. text.php
    2. plain.php
    3. text_plain.php

  2. attachment.php
  3. single-attachment.php
  4. single.php
  5. index.php

您可以为附件设置特定于 MIME 类型的模板.例如,在我的博客上,我有一个 JavaScript Meetup 使用处理图像附件的 mime 类型特定的 image.php 附件模板.

因此,如果您处理图像,那么我建议您创建一个 image.php 文件并将其放入您的主题文件夹并开始工作.

I am building my first Wordpress theme. I am having trouble with media attachment. When I upload and image, and insert it into the post, it shows the image. If I link it to "Media File" then it also takes me to the file when clicked upon. But if I try to link to "attachment-page" it does not show the image. I am NOT using a custom 'attachment.php' instead I'm only using the default 'single.php'. Here is the code of single.php:

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    <div class="post" id="post-<?php the_ID(); ?>">
        <div>
        <h2><?php the_title(); ?></h2>

        <?php include (TEMPLATEPATH . '/inc/meta.php' ); ?>

        <div class="entry">

            <?php the_content(); ?>

            <?php wp_link_pages(array('before' => 'Pages: ', 'next_or_number' => 'number')); ?>

        </div>

        <?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>

    </div>
    </div>
    <?php // comments_template(); ?>

    <?php endwhile; endif; ?>


</div> <!--main-content Ends--> 

解决方案

@Zeeshan

Your single.php document does not appear to have the proper PHP code to output the attachments. Try adding the following code within the loop, wherever you'd like the attachment content to show up:

<?php if(wp_attachment_is_image($post->id)) : $att_image = wp_get_attachment_image_src($post->id, "full"); ?>
  <p class="attachment"><a class="show_image" href="<?php echo wp_get_attachment_url($post->id); ?>" title="<?php echo get_the_title(); ?>"><img class="img-responsive attachment-medium" src="<?php echo $att_image[0]; ?>" height="<?php echo $att_image[2];?>" width="<?php echo $att_image[1];?>" alt="<?php echo get_the_title(); ?>"></a></p>
<?php else : ?>
    <a href="<?php echo wp_get_attachment_url($post->ID) ?>" title="<?php echo wp_specialchars( get_the_title($post->ID), 1 ) ?>"><?php echo basename($post->guid) ?></a>
<?php endif; ?>

This code works with the latest 3.x CORE but also has a fallback for older versions.

If provided, the_content() function outputs the media description.

Attachment pages range from using simply attachment.php file to almost a dozen other template files.

http://codex.wordpress.org/Template_Hierarchy#Attachment_display

Attachment display

Template file used to render a single attachment (attachment post-type) page.

  1. MIME_type.php - it can be any MIME type (image.php, video.php, application.php). For text/plain, in order:

    1. text.php
    2. plain.php
    3. text_plain.php

  2. attachment.php
  3. single-attachment.php
  4. single.php
  5. index.php

You can have mime type specific templates for attachments. For example, over at my blog I have a snapshot of a JavaScript Meetup using the mime type specific image.php attachment template that handles image attachments.

So if your dealing with images, then I suggest you create an image.php file and drop that into your themes folder and get to work.

这篇关于wp 附件页面不显示媒体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆