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

Using Storyline Tags on Single Pages #222

Closed Kuriousity closed 9 years ago

Kuriousity commented 9 years ago

I'm trying to pull storyline-specific information onto a single comic page, but none of the template codes are working for me unless used specifically in the archives. It seems like it'd be an obvious feature so I'm afraid I'm just missing something in the code that makes this work.

I'd like to display the title, cover, and description, for a comic page's storyline on its comics' pages. Is this possible? Or is this missing?

Mihari commented 9 years ago

By chance, which codes are you using?

Kuriousity commented 9 years ago

I'm trying to use codes such as: webcomic_storyline_cover(); and webcomic_storyline_title();

I would like them to work on single comic pages so they display the cover and title for the storyline the comic page is in. This works for collections (so I can show the collection poster) but not for storylines.

mgsisk commented 9 years ago

It is possible to use them on single-webcomic pages, but it's a little more complicated than using the collection tags. The next paragraph explains why; skip to the third paragraph for a potential answer to your question.

The collection tags work automatically on single posts because Webcomic always knows what collection a Webcomic post belongs to (it can only belong to one). A Webcomic post can belong to any number of storylines, though, so using webcomic_storyline_cover() on a single-Webcomic post doesn't work automatically, as Webcomic can't know which storyline you mean. Even if your Webcomic posts never belong to more than one storyline Webcomic won't try to guess which one you mean.

The trick to getting these storyline (and character) tags to work outside of the usual taxonomy archives is to specify which storyline you mean. Each of webcomic_storyline_title(), webcomic_storyline_cover(), and webcomic_storyline_description() has an argument that allows you to specify the storyline to display the title, cover, or description for. First, you'll have to grab the storyline ID's that are associated with the Webcomic post (all of the following code should work anywhere in the loop):

<?php $storyline = wp_get_post_terms(get_the_ID(), get_the_collection() . '_storyline', array('fields' => 'ids')); ?>

This line should return an array of storyline ID's that the current Webcomic post belongs to. Now we can iterate through them, like:

<?php
    //First, let's save the collection ID so we don't have to repeatedly call this function.
    $collection = get_webcomic_collection(); 

    // Next, we'll iterate through all of the storyline ID's and display info for each.
    foreach ($storylines as $sid) {
        webcomit_storyline_title('', $sid, $collection);
        webcomit_storyline_cover('full', $sid, $collection);
        webcomit_storyline_description($sid, $collection);
    }
?>
ashikai commented 8 years ago

Hey, I know this issue is closed, but the code here has a couple typos in it that throw fatal errors. I think it should read:

<?php
$storyline = wp_get_post_terms(get_the_ID(), get_webcomic_collection() . '_storyline', array('fields' => 'ids'));
    //First, let's save the collection ID so we don't have to repeatedly call this function.
    $collection = get_webcomic_collection(); 

    // Next, we'll iterate through all of the storyline ID's and display info for each.
    foreach ($storyline as $sid) {
        webcomic_storyline_title('', $sid, $collection);
        webcomic_storyline_cover('full', $sid, $collection);
        webcomic_storyline_description($sid, $collection);
    }
?>

This was the only way I could get it to work, anyway. o.o/