Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display webcomic thumbnail/first image #325

Closed
misternek opened this issue Aug 29, 2018 · 4 comments
Closed

Display webcomic thumbnail/first image #325

misternek opened this issue Aug 29, 2018 · 4 comments
Assignees
Labels

Comments

@misternek
Copy link

misternek commented Aug 29, 2018

I'm trying to develop a custom Webcomic theme for my own website, and I'm at the point where I'm creating the archive.php page:

<div id="gallery">
<?php if (have_posts()) : ?><?php while (have_posts()) : the_post(); ?>

<a href="<?php the_permalink(); ?>"><?php webcomic_media(); ?></a>

<?php endwhile; ?><?php else : ?>
<?php endif; ?>
</div>

It's working fine until I make a webcomic post with more than one piece of media. When I do that it display all of the post's media on the page, when I only want one thumbnail image. I've tried the default Wordpress thumbnail tag and that doesn't return any images. I've also looked at the wiki but it's not entirely clear to me how to configure the tag to just show one image from the post.

Sorry if this sounds like a noob question, I only have the most basic knowledge of PHP.

@mgsisk mgsisk self-assigned this Aug 31, 2018
@mgsisk
Copy link
Owner

mgsisk commented Aug 31, 2018

Hey @misternek, that's great that you're doing a custom Webcomic theme! I'd love to see it when you're done.

The documentation for webcomic_media() is a little obtuse, but this should get you the result you're looking for:

<?php webcomic_media( 'full', null, [ 'length' => 1 ] ); ?>

The first argument is the size of the media you want to display, the second is the post you want to display media for (null here so that we default to the loop's current post), and the last is an array with the length key set to 1, which is what should actually limit how many media items are displayed.

@misternek
Copy link
Author

misternek commented Aug 31, 2018

Hi @mgsisk! Unfortunately this code isn't fixing the problem. The archive page is still showing all of my gallery post's media:

galleryissue

Here is my entire archive.php file if it helps. I also tried resetting the permalinks and renaming it to archive-webcomic1.php and got the same results.

<?php get_header(); ?>

<div id="gallery">
<?php if (have_posts()) : ?><?php while (have_posts()) : the_post(); ?>

<a href="<?php the_permalink(); ?>"><?php webcomic_media( 'full', null, [ 'length' => 1 ] ); ?></a>

<?php endwhile; ?><?php else : ?>
<!-- 404 text will go here -->
<?php endif; ?>
</div>

<?php get_footer(); ?>

@mgsisk
Copy link
Owner

mgsisk commented Sep 2, 2018

Thanks @misternek; totally my fault. The length argument requires the offset argument, as well, but of course I forgot that. Try this one:

<?php webcomic_media( 'full', null, [ 'offset' => 0, 'length' => 1 ] ); ?>

The offset and length arguments work together; here, they're telling Webcomic "of all the media this post has, start at the first media item (offset => 0) and just show one (length => 1).

@misternek
Copy link
Author

This worked perfectly, thank you @mgsisk!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants