Photos and custom attachments in Wordpress

2

I need to put gallery of photos and attachments in the posts and pages of Wordpress, but with a custom style in the view inside the post.

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

I want to link the images / files in the post to show when to see the post .

    
asked by anonymous 31.03.2015 / 13:08

1 answer

2

Use an attachment plugin

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

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

Viewing attachments

Each plugin will also have a way for you to include the files in the post and page view.

Some plugins provide shortcodes , which is a short text that you place within the article content and the plugin automatically adds content.

Another way is by using code directly on the screens. The plugin quoted 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; ?>

Viewing images

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

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

    
02.04.2015 / 18:09