thenewinquiry / tni-core-functionality

Contains the site's core functionality.
GNU General Public License v2.0
2 stars 0 forks source link

Post bundling #40

Closed frnsys closed 7 years ago

frnsys commented 7 years ago

We need a feature where we can assign posts to "bundles" which we can then present on the home page.

@misfist how long do you think something like this would take? also let me know if you have any questions

misfist commented 7 years ago

If I understand correctly, you're looking to:

  1. to be able to associate a post with one or more (or none) bundles
  2. select up to 1 bundle to be featured on the home page
  3. the posts within a featured bundle would appear on the home page like other posts
  4. the bundle name would be displayed on the post

The most straight-forward approach would be to add a taxonomy for Bundles to which you'd add bundle terms.

We'd then add to the Featured Content page (/wp/wp-admin/admin.php?page=featured-content ) a selector to pick the featured Bundle.

Question: Do you want to prevent the featured bundle posts from being repeated in the post list?

If so, we'd probably want to do something similar to what we did with tni_core_get_unauthorized_posts() function that caches the result for a certain period of time.

I think this would take 2-4 hours.

frnsys commented 7 years ago

To clarify on 3, the posts within a featured bundle show up independently from the rest of the loop and yes let's keep bundled posts from repeating in the post list.

So if I have articles A-I, and am displaying a bundle with articles D, F, and G, the homepage layout might look like:

Bundle Title
D  F  G            

(regular posts)
A B C
E H I

let me know if it still needs clarifying. thanks!

misfist commented 7 years ago

So, the bundle won't be in the flow of the rest of the posts and they ought not repeat. Got it.

frnsys commented 7 years ago

@misfist it's looking great so far, thank you!

A couple small additions came up for the bundles:

image

I can take care of all the themeing stuff if you add in the necessary fields and tell me how to access them.

thanks!

misfist commented 7 years ago

The terms have a description field, by default. /wp/wp-admin/edit-tags.php?taxonomy=bundle You can access it with term_description( $post->ID, 'bundle' ).

<?php if( $term_description = term_description( $term_id, 'bundle' ) ) : ?>
   <?php echo $term_description; ?>
<?php endif; ?> 

A term image plugin is currently installed, which adds the ability to associate an image with an taxonomy term. Happily, it just uses native WP term meta, so it's easy to get (custom fields for taxonomy terms).

<?php /* image id is stored as term meta */
if( $image_id = get_term_meta( $term_id, 'image', true ) ) : ?>

   <?php 
    /* Replace `$image_size = 'thumbnail'` with the size you want to use (probably 'full') */
   $image_data = wp_get_attachment_image_src( $image_id, $image_size = 'thumbnail' ); ?>

   <?php
    /* image data is stored in array; image `url` is the first item */
   $image = $image_data[0]; ?>

   <?php if( !empty( $image ) ) : ?>
     <img src='<?php echo esc_url( $image ); ?>" />
   <?php endif; ?>

<?php endif; ?> 

Our $term_id is the ID of the bundle. We're already getting it on the home page.

$featured_bundle = get_option( 'options_featured_bundle' );

You'll want to convert it to an integer when you use it to get the image and description.

$term_description = term_description( (int) $term_id, 'bundle' ) 
$image_id = get_term_meta( (int) $term_id, 'image', true )

I'm happy to add this if you like. Let me know.

misfist commented 7 years ago

Also, I replaced the category link under the post image with the bundle link. Is that what you wanted?

frnsys commented 7 years ago

Ah fantastic, I'll just use what we have then.

I'm not sure what to use yet under the post image, I need to experiment a bit, but I can take it from here. thanks!