mgsisk / webcomic

Comic publishing power for the web. Turn your WordPress-powered site into a comic publishing platform with Webcomic.
http://wordpress.org/plugins/webcomic
GNU General Public License v2.0
110 stars 29 forks source link

Question about character archive template #175

Closed MerrilyDuffy closed 10 years ago

MerrilyDuffy commented 10 years ago

Hey Michael,

Is it possible to limit the comics listed via the webcomic_list_characters template tag on a character page to only those that that specific character appears in?

For example, here is my character cast page:

http://www.poseurpatrol.com/cast/

And for testing purposes, I have the character at the end, Mistress Diana, linked to her individual character page:

http://www.poseurpatrol.com/characters/mistressdiana/

Diana only appears in the comics of those last two thumbnails. So, can one prevent the others from displaying, or is there no way of stopping all of them being listed? (I don't comprehend all of the arguments for that particular template tag listed in the wiki).

This is what I have so far in my character archive template


<?php
get_header();
$webcomic_group      = true;
$webcomic_image      = true;
$webcomic_collection = 'webcomic1';
?><br><br>
<center>
<main role="main">
<?php webcomic_character_avatar( $size = 'full',  $character,  $collection = '' ); ?><br><br><br><br>
<?php webcomic_list_characters( array( 'collection' => 'webcomic1', 'webcomics' => true, 'webcomic_image' => 'thumbnail' ) ); ?>
</main><br><br>© copyright 2011-2014<br>
<a href="http://www.blackfairypress.com/">Black Fairy Press/Merrily Duffy</a><br><br>
</center>

Thanks much,

Merrily

mgsisk commented 10 years ago

The character archive pages are functionally identical to WordPress category or tag archives, so it should only be showing those webcomics that are "tagged" as having Mistress Diana appearing in them. It looks like she definitely wasn't tagged in at least one of those other comics (I found a character list hiding in your source), but looking at the source for the character archive page I can see that it's actually listing out all the characters—including the comics they appear—which is why everything is showing up on her page.

I don't think there's any way to get webcomic_list_character to work the way you want in this case; it's sort of designed to list all the characters (and their comics, if you choose). If this is an actual character archive you can use a standard WordPress loop to display only the comics Mistress Diana is in, like (I stole this from Inkblot's webcomic/archive.php template; you may need to tweak it a bit):

<?php inkblot_posts_nav( 'above' ); ?>
<?php while ( have_posts() ) : the_post(); ?>
    <?php the_webcomic( "medium", "self" ); ?>
<?php endwhile; ?>
<?php inkblot_posts_nav( 'below' ); ?>

By default the archives are paged based on your WordPress reading settings; if you want all the comics displayed on the one page (as webcomic_lsit_characters would do), we can do a custom loop like:

<?php
$comics = new WP_Query( array(
    "posts_per_page" => -1, // get all posts
    "tax_query" => array(
        "taxonomy" => "webcomic1_character", // or whatever collection, e.g. webcomic42_character
        "terms" => get_queried_object()->term_id // the current character ID
    ),
    "post_status" => array( // this bit and the next ensures that only published posts are retrieved; without it, *any* posts will be retreived
        "publish",
        "private"
    ),
    "perm" => "readable"
) );
?>

<?php if ( $comics->have_posts() ) : ?>

    <?php while ( $comics->have_posts() ) : $comics->the_post(); ?>
        <?php the_webcomic( "medium", "self" ); ?>
    <?php endwhile; ?>

<?php endif; ?>

Apologies if that doesn't work; I haven't actually tested it. If you do try it let me know how it goes.

MerrilyDuffy commented 10 years ago

Thanks for the quick response. I appreciate it, especially during the holidays. I can't get it to work yet, but will keep trying...

MerrilyDuffy commented 10 years ago

Okay. Getting closer...

So I read through the wiki again and noticed I overlooked the_related_webcomics template tag, and decided to try it out in my character archive:

<?php get_header(); ?>

<br><br>

<center>

<main role="main">
<?php webcomic_character_avatar( $size = 'full',  $character,  $collection = '' ); ?>

<br><br><br><br>

<?php the_related_webcomics( '<ol class="related-webcomics"><li>', '</li><li>', '</li></ol>', 'thumbnail', 0, false, true, false ); ?>
</main>

<br><br>

© copyright 2011-2014

<br>

<a href="http://www.blackfairypress.com/">Black Fairy Press/Merrily Duffy</a>

<br><br>

</center>

I went and finished tagging all of my characters on every page (except the main characters Victoria & Jax), and linked their images on my cast page to their character pages.

http://www.poseurpatrol.com/cast/

Just as I had wanted, I am getting ordered lists of all of the comics the individual characters appear in--except for their very first appearances. For example, Tiffany/Crystal Moon's first appearance is on page two of chapter five:

http://www.poseurpatrol.com/comics/tpip-02/

But her character page is showing page three (tpip-03) as her first appearance:

http://www.poseurpatrol.com/characters/tiffanycrystalmoon/

MerrilyDuffy commented 10 years ago

Figured it out now. Adding the_webcomic template tag was sufficient to fix the problem. Here is my final character archive for anyone reading the thread:


<?php get_header(); ?>

<br><br>

<center>

<main role="main">

<?php webcomic_character_avatar( $size = 'full',  $character,  $collection = '' ); ?>

<br><br><br><br><br>

<?php webcomic_character_title(); ?> appearances:

<br><br><br>

<?php the_webcomic( 'thumbnail', 'self', false, false, 'character', false ); ?>

<?php the_related_webcomics( '<ol class="related-webcomics"><li>', '</li><li>', '</li></ol>', 'thumbnail', 0, false, true, false ); ?>

</main>

<br><br>

© copyright 2011-2014

<br>

<a href="http://www.blackfairypress.com/">Black Fairy Press/Merrily Duffy</a>

<br><br>

</center>

Thanks Michael, for the help, and your continuing work on this plugin,

Merrily

MerrilyDuffy commented 10 years ago

One more thing for anyone reading, the_related_webcomics template tag creates an ordered list with numerals, so to hide the numbers as I have, use this in your style sheet:


ol {
list-style-type: none;
}
MerrilyDuffy commented 10 years ago

Oops. Hit a another snag. If you go back and add new characters to an existing webcomic, the character archives get mucked up...

MerrilyDuffy commented 10 years ago

Also something odd happening: sometimes one gets the correct result when landing on a character archive page, and sometimes not. For example Mistress Diana's page sometimes has the correct number of thumbnails, which is two, and sometimes not; and if one refreshes the page after getting the correct number of thumbnails, it displays other thumbnails she isn't tagged in. One can refresh it yet again, and then get the correct results again. I can't figure out what I'm doing wrong...

mgsisk commented 10 years ago

The problems are probably caused by the_related_webcomcis, which also isn't really designed for this. It grabs webcomics in random order (excluding the current webcomic, which is probably why the first webcomic is always excluded on the archive pages). Here's some updated custom loop code that I have tested and should work for your character archives.

    <?php
    $comics = new WP_Query( array(
        "posts_per_page" => -1, // get all posts
        "tax_query" => array(
            array(
                "taxonomy" => "webcomic1_character", // or whatever collection, e.g. webcomic42_character
                "terms" => get_queried_object()->term_id, // the current character ID
                "field" => "id"
            )
        ),
        "post_status" => array( // this bit and the next ensures that only published posts are retrieved; without it, *any* posts will be retreived
            "publish"
        ),
        "post_type" => "webcomic1",
        "perm" => "readable",
        "order" => "ASC"
    ) );
    ?>

    <?php if ( $comics->have_posts() ) : ?>
        <ul>
        <?php while ( $comics->have_posts() ) : $comics->the_post(); ?>
            <li><?php the_title(); the_webcomic( "medium", "self" ); ?></li>
        <?php endwhile; ?>
        </ul>
    <?php endif; ?>
MerrilyDuffy commented 10 years ago

Ah, thank you! That did the trick. Have a great week.