Custom Photos and Attachments in Wordpress

Asked

Viewed 276 times

2

I need to put photo gallery and attachments files in posts and Wordpress pages, but with a custom style in the display within the post.

How do I just upload the images and files in the edit, linked them with the post, and then on view consult to display them?

I want to link the images/files on post to be able to display when viewing the post.

1 answer

2


Use an attachment plugin

To link files to the post you can use a plugin like this. I have not used this plugin and there are others, so search well and choose one of them.

These attachment plugins will add fields in editing posts and pages for you to associate files.

Displaying the attachments

Each plugin will also have a way for you to include the files in the preview of posts and pages.

Some plugins make available shortcodes, which is a small text that you put inside the content of the article and the plugin automatically adds the content.

Another way is by using code directly on the screens. The plugin cited above gives the following example:

<?php $attachments = new Attachments( 'attachments' ); /* pass the instance name */ ?>
<?php if( $attachments->exist() ) : ?>
  <h3>Attachments</h3>
  <p>Total Attachments: <?php echo $attachments->total(); ?></p>
  <ul>
    <?php while( $attachments->get() ) : ?>
      <li>
        ID: <?php echo $attachments->id(); ?><br />
        Type: <?php echo $attachments->type(); ?><br />
        Subtype: <?php echo $attachments->subtype(); ?><br />
        URL: <?php echo $attachments->url(); ?><br />
        Image: <?php echo $attachments->image( 'thumbnail' ); ?><br />
        Source: <?php echo $attachments->src( 'full' ); ?><br />
        Size: <?php echo $attachments->filesize(); ?><br />
        Title Field: <?php echo $attachments->field( 'title' ); ?><br />
        Caption Field: <?php echo $attachments->field( 'caption' ); ?>
      </li>
    <?php endwhile; ?>
  </ul>
<?php endif; ?>

Displaying images

Possibly it is possible to use the same attachment plugin to display the images. Just filter the files that are images and display using the tag <img>.

If you want another alternative, search for another plugin specifically for image gallery. There are several there that allow you to create galleries and show with shortcodes or custom code.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.