WordPress.org

Ready to get started?Download WordPress

Forums

generate single pages based on custom meta? (6 posts)

  1. dadako
    Member
    Posted 3 months ago #

    I'm trying to be as conservative as possible with my posts in a new wordpress site and let custom meta generate content across the site.

    One of my custom meta tags is "video", in it I place a link to a youtube video that relates to the article.

    The articles can be in one of three categories. Some don't have video so I query that up front.

    As a result I can generate a category called "video", this page just lists any post with the "video" custom meta:

    <?php
    $recentPosts = new WP_Query();
    $recentPosts->query('cat=1,2,3');
    while ($recentPosts->have_posts()) :
    $recentPosts->the_post();
    ?>
    <?php if (get_post_meta($post->ID, "video", true)) : ?>
    <a href="<?php the_permalink(); ?>"><?php the_title(''); ?></a>
    <?php endif;?>
    <?php endwhile; ?>

    Clicking on the resulting link here will take a user to the post containing the video, so far so good. The post will be displayed in it's relevant category template.

    However what I'd like to achieve is that when the link is clicked, the user is taken to an entirely new single-post template that displays the video meta data & title, but in it's own post format regardless of the category the post is in (not the category template).

    Really not sure where to start, other than making separate posts for videos in their own category, which would be doubling up of data.

    Any advice very welcome.

  2. bcworkz
    Member
    Posted 3 months ago #

    You used the term "post format". I'm unsure if you mean format in a general sense or the specific WP post_format taxonomy. Either way, the taxonomy is what you should use. Not all themes support post formats, but you can modify your theme to support Post Formats if it does not. The additional code required should be specified in a child theme.

    There already is a "video" post format defined. If that term is applied to a post, that single post will be displayed using the content-video.php template if it exists. (The 'content' part is actually theme specific, but 'content' is used almost universally.)

    Once post support is enabled, you can specify the format when creating a post, or do so by script anytime the video post meta value exists.

  3. dadako
    Member
    Posted 3 months ago #

    Thanks bcworkz, I'll look into post formats, sounds like exactly what I am looking for!

  4. dadako
    Member
    Posted 3 months ago #

    Investigated further and I don't think post formats can cover it.

    Post formats is basically the same as categories, I'm trying to make the same post (same data) show differently in different stand alone single views using different links.

  5. dadako
    Member
    Posted 3 months ago #

    post formats can also be achieved with "single-[cat name].php" docs, which I'm already doing.

  6. bcworkz
    Member
    Posted 3 months ago #

    I think I understand, which I did not initially, sorry for the misdirection. In this case I think you need to basically have two templates in one with a conditional that decides which version to use by which link was used to get there.

Reply

You must log in to post.

About this Topic