-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Single project view #140
Single project view #140
Changes from 6 commits
0297aac
37e97c4
4dfbf7f
09b6936
b417fd5
44ef1ff
554eded
8a616c2
fd762e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -409,4 +409,4 @@ function largo_excerpt( $the_post = null, $sentence_count = 5, $use_more = null, | |
|
||
return $output; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,54 @@ | ||
var $ = jQuery; | ||
$(document).ready(function(){ | ||
|
||
current_ltw_projects_load_param_project_if_exists(); | ||
|
||
$( ".projects-list article .entry-title a" ).click(function(e){ | ||
e.preventDefault(); | ||
var post_id = $(this).data("post-id"); | ||
current_ltw_projects_load_single_project(post_id); | ||
}); | ||
|
||
}); | ||
|
||
/** | ||
* Function to load the single project partial for whatever project | ||
* is provided. | ||
* | ||
* @param int post_id The id of the project we want to load | ||
*/ | ||
function current_ltw_projects_load_single_project( post_id ) { | ||
|
||
// give a reassuring "loading" notice | ||
$(".projects-single-holder").html("Loading project..."); | ||
|
||
// actually load the single project | ||
$(".projects-single-holder").load(ajax_object.ajax_url+"?action=load_more_post&post_id="+post_id); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider https://current.test/ltw-test-page/ and the per-project page https://current.test/ltw-test-page/?project_id=3251741: On page load, https://current.test/ltw-test-page/ displays in the single-project area the final post from the queue, which is the last item in the post list. The DOM looks like this: <div class="projects-single-holder">
<h1 class="projects-single-title">Youth Reporting Institute</h1>
....
</div> Styles on Clicking on the last item in the list loads the post: <div class="projects-single-holder">
<div class="projects-single-holder">
<h1 class="projects-single-title">Youth Reporting Institute</h1>
....
</div>
</div> The post now has a double black outline. Loading the project-specific URL https://current.test/ltw-test-page/?project_id=3251741 means that that project is, upon page load, queried for by JS and then loaded by JS: <div class="projects-single-holder">
<div class="projects-single-holder">
<h1 class="projects-single-title">Youth Reporting Institute</h1>
....
</div>
</div> The post now has a double black outline. In conclusion: loading the project via JS means that we get an extra
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @benlk I noticed that too and wanted to hear your opinion on what you think would be best. I think splitting up the "holder" and the "held" sounds like a viable solution. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #140 (comment) explores a little more the holder/held distinction; I think what we'd end up with is:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
// return and let's be happy | ||
return; | ||
|
||
} | ||
|
||
/** | ||
* Fires on page load to check if a post_id query param is set | ||
* If it is set, attemps to load the specified project by the ID given | ||
*/ | ||
function current_ltw_projects_load_param_project_if_exists() { | ||
|
||
// find all current query params | ||
var get_url_params = new URLSearchParams(window.location.search); | ||
|
||
// if the post id query param exists, let's use it | ||
if(get_url_params.get('project_id') || Number.isInteger(get_url_params.get('project_id'))) { | ||
|
||
var post_id = get_url_params.get('project_id'); | ||
|
||
// actually try and load the project | ||
current_ltw_projects_load_single_project( post_id ); | ||
|
||
return; | ||
|
||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ | |
<article id="post-<?php the_ID(); ?>" <?php post_class('clearfix projects-list-item'); ?>> | ||
|
||
<?php | ||
|
||
echo '<div class="' . $entry_classes . '">'; | ||
|
||
if ( largo_has_categories_or_tags() ) { | ||
|
@@ -43,15 +44,15 @@ | |
?> | ||
|
||
<h2 class="entry-title"> | ||
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute( array( 'before' => __( 'Permalink to', 'largo' ) . ' ' ) )?>" rel="bookmark"><?php the_title(); ?></a> | ||
<a href="?project_id=<?php echo get_the_ID(); ?>" title="<?php the_title_attribute( array( 'before' => __( 'Permalink to', 'largo' ) . ' ' ) )?>" rel="bookmark" data-post-id="<?php echo get_the_ID(); ?>"><?php the_title(); ?></a> | ||
</h2> | ||
|
||
<?php | ||
// we may need to redo these links as search query params instead | ||
$status = get_the_terms( get_the_ID(), 'project-status' ); | ||
$categories = get_the_terms( get_the_ID(), 'project-category' ); | ||
// @todo this throws errors when no terms are found for this type of post | ||
if ( is_array( $status) && is_array( $status ) ) { | ||
if ( is_array( $status) && is_array( $categories ) ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the catch. 👍 |
||
$terms = array_merge( $status, $categories ); | ||
} else if ( is_array( $status ) ) { | ||
$terms = $status; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,183 @@ | ||
<?php | ||
|
||
$args = array ( | ||
// post-specific, should probably not be filtered but may be useful | ||
'post_id' => $post->ID, | ||
'hero_class' => largo_hero_class( $post->ID, FALSE ), | ||
|
||
// only used to determine the existence of a youtube_url | ||
'values' => get_post_custom( $post->ID ), | ||
|
||
// this should be filtered in the event of a term-specific archive | ||
'featured' => false, | ||
|
||
// $show_thumbnail does not control whether or not the thumbnail is displayed; | ||
// it controls whether or not the thumbnail is displayed normally. | ||
'show_thumbnail' => TRUE, | ||
'show_excerpt' => TRUE, | ||
); | ||
|
||
$args = apply_filters( 'largo_content_partial_arguments', $args, get_queried_object() ); | ||
|
||
extract( $args ); | ||
|
||
$entry_classes = 'entry-content'; | ||
|
||
$show_top_tag = largo_has_categories_or_tags(); | ||
|
||
$custom = get_post_custom(); | ||
|
||
if ( $featured ) { | ||
$entry_classes .= ' span10 with-hero'; | ||
$show_thumbnail = FALSE; | ||
} | ||
if( ! empty ( $custom['project-video'][0] ) ) { | ||
$show_youtube = TRUE; | ||
$show_thumbnail = FALSE; | ||
} | ||
|
||
?> | ||
<div class="projects-single-holder"> | ||
<h3>Single project goes here.</h3> | ||
<h1 class="projects-single-title"><?php echo the_title(); ?></h1> | ||
<?php | ||
|
||
echo '<div class="' . $entry_classes . '">'; | ||
|
||
// we may need to redo these links as search query params instead | ||
$status = get_the_terms( get_the_ID(), 'project-status' ); | ||
$categories = get_the_terms( get_the_ID(), 'project-category' ); | ||
// @todo this throws errors when no terms are found for this type of post | ||
if ( is_array( $status ) && is_array( $categories ) ) { | ||
$terms = array_merge( $status, $categories ); | ||
} else if ( is_array( $status ) ) { | ||
$terms = $status; | ||
} else if ( is_array( $categories ) ) { | ||
$terms = $categories; | ||
} else { | ||
$terms = array(); | ||
} | ||
|
||
if ( ! empty( $terms ) ) { | ||
echo '<ul class="project-tags">'; | ||
$terms_count = count( $terms ); | ||
$terms_index = 0; | ||
$delimiter = ' | '; | ||
foreach ( $terms as $term ) { | ||
$terms_index++; | ||
printf( | ||
'<a class="project-tag %1$s-%2$s" href="%3$s">%4$s </a>', | ||
esc_attr( $term->taxonomy ), | ||
esc_attr( $term->slug ), | ||
// @todo: make this be a link that triggers the search filter for this term | ||
get_term_link( $term ), | ||
esc_html( $term->name ), | ||
); | ||
if( $terms_index != $terms_count ){ | ||
echo '<span class="delimiter">' . $delimiter . '</span>'; | ||
} | ||
} | ||
echo '</ul>'; | ||
} | ||
|
||
// thumbnail or video | ||
if ( $show_thumbnail ) { | ||
echo '<div class="has-thumbnail '.$hero_class.'"><a href="?project_id=' . get_the_ID() . '">' . get_the_post_thumbnail() . '</a></div>'; | ||
} else if( $show_youtube && wp_oembed_get( $custom['project-video'][0] ) ) { | ||
echo wp_oembed_get( $custom['project-video'][0] ); | ||
} | ||
|
||
// organization | ||
if ( ! empty( $custom['project-organization'][0] ) ) { | ||
printf( | ||
'<div><label class="project-single-organization">%1$s:</label> | ||
<span class="project-organization">%2$s</span></div>', | ||
__( 'Organization', 'current-ltw-projects' ), | ||
esc_html( $custom['project-organization'][0] ) | ||
); | ||
} | ||
|
||
// year submitted | ||
printf( | ||
'<div><label class="project-single-submission-year">%1$s:</label> | ||
<span class="project-submission-year">%2$s</span></div>', | ||
__( 'Year Submitted', 'current-ltw-projects' ), | ||
get_the_date( 'Y' ) | ||
); | ||
|
||
// type of org | ||
$org_types = get_the_terms( get_the_ID(), 'project-org-type' ); | ||
if ( ! empty( $org_types ) ) { | ||
$delimiter = ', '; | ||
$org_types_count = count( $org_types ); | ||
$org_type_index = 0; | ||
_e( '<div><label class="project-org-types-label">Type of Organization: </label>', 'current-ltw-projects' ); | ||
foreach ( $org_types as $org_type ) { | ||
$org_type_index++; | ||
printf( | ||
'<a href="%3$s">%4$s</a>', | ||
esc_attr( $org_type->taxonomy ), | ||
esc_attr( $org_type->slug ), | ||
// @todo: make this be a link that triggers the search filter for this term | ||
get_term_link( $org_type ), | ||
esc_html( $org_type->name ) | ||
); | ||
if( $org_type_index != $org_types_count ){ | ||
echo '<span class="comma-delimiter">' . $delimiter . '</span>'; | ||
} | ||
} | ||
echo '</ul></div>'; | ||
} | ||
|
||
// contact name and email | ||
if ( ! empty( $custom['project-contact-name'][0] ) || ! empty( $custom['project-contact-email'] ) ) { | ||
printf( | ||
'<label class="project-single-contact">%1$s: </label>', | ||
__( 'Contact', 'current-ltw-projects' ), | ||
); | ||
} | ||
|
||
if ( ! empty( $custom['project-contact-name'][0] ) ) { | ||
printf( | ||
'<span class="project-contact-name">%1$s</span><br/>', | ||
esc_html( $custom['project-contact-name'][0] ) | ||
); | ||
} | ||
|
||
if ( ! empty( $custom['project-contact-email'][0] ) ) { | ||
printf( | ||
'<span class="project-contact-email">%1$s</span>', | ||
esc_html( $custom['project-contact-email'][0] ) | ||
); | ||
} | ||
|
||
// tell your story / main content | ||
the_content(); | ||
|
||
// project revenue | ||
if ( ! empty( $custom['project-revenue'][0] ) ) { | ||
printf( | ||
'<p class="project-revenue">%1$s</p>', | ||
esc_html( $custom['project-revenue'][0] ) | ||
); | ||
} | ||
|
||
// specific impact | ||
if ( ! empty( $custom['project-impact'][0] ) ) { | ||
printf( | ||
'<p class="project-specific-impact">%1$s</p>', | ||
esc_html( $custom['project-impact'][0] ) | ||
); | ||
} | ||
|
||
// primary url | ||
if ( ! empty( $custom['project-link'][0] ) ) { | ||
printf( | ||
'<label class="project-specific-link">%1$s:</label> | ||
<a class="project-specific-link" href="%2$s" target="_blank">%2$s</a>', | ||
__( 'Project Specific Link', 'current-ltw-projects' ), | ||
esc_html( $custom['project-link'][0] ) | ||
); | ||
} | ||
|
||
?> | ||
</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be sanitized; since post IDs are always integers we could do
abs(intval( $post_id ))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in 554eded