Community Forums › Forums › Archived Forums › Design Tips and Tricks › Adding a function to functions.php
Tagged: genesis_after_entry_content, WP Broadbean
- This topic has 4 replies, 2 voices, and was last updated 4 years, 7 months ago by Brad Dalton.
-
AuthorPosts
-
September 26, 2019 at 9:59 am #493728PhilMurrayParticipant
hi - I am trying to get output from a plugin to appear at the bottom of POSTS on the ARCHIVE page
i am using a child theme based on Genesis Sample Theme
what i need to do is add the following function into the ARCHIVES page and have it placed at genesis_after_entry_content
so my question is how do I achieve that? is it by adding the function to functions.php in my child theme? if so - what parameters do i need to use?
the function is;
/**
* Gets the jobs data (fields and terms) associated with a job.
*
* @param array $args An array of args in terms of what to show. See $defaults.
* @return mixed false if there is no data or a string of html if there is.
*/
function wpbb_get_job_meta_data( $args = array() ) {
// string to hold meta data in.
$meta_output = '';
// string to hold taxonomy data in.
$tax_output = '';
// entire output string.
$output = '';
global $post;
// set some defaults for the args.
$defaults = array(
'post_id' => $post->ID,
'taxonomies' => wpbb_get_registered_taxonomies(),
'meta' => wpbb_get_job_fields(),
'show_title' => true,
);
// merge defaults with args.
$args = wp_parse_args( $args, $defaults );
// add the wrapper start.
$output .= '<div class="wpbb-job-data__wrapper">';
// if we should output the title.
if ( true === $args['show_title'] ) {
// add the title next.
$output .= '<h3 class="wpbb-job-data__title">' . esc_html__( 'Job Information', 'wproadbean' ) . '</h3>';
}
// add the job data div.
$output .= '<div class="wpbb-job-data">';
// handle the job fields first if we have any to handle.
if ( ! empty( $args['meta'] ) ) {
// loop through each meta.
foreach ( $args['meta'] as $field ) {
// get the value of this field.
$field_value = get_post_meta( $args['post_id'], $field['id'], true );
// make sure we have a show_on_frontend set.
if ( ! isset( $field['show_on_frontend'] ) ) {
// set to show on both archive and single views.
$field['show_on_frontend'] = array( 'single', 'archive' );
}
// if we are not showing this data on the front end.
if ( false === $field['show_on_frontend'] ) {
continue;
}
// if this is the salary from or salary to field.
if ( wpbb_get_job_field_prefix() . 'salary_from' === $field['id'] || wpbb_get_job_field_prefix() . 'salary_to' === $field['id'] ) {
$value_prefix = wpbb_get_job_currency_symbol( $args['post_id'] );
} else {
$value_prefix = '';
}
// add this field to the output string.
$meta_output .= '<div class="wpbb-job-data__field wpbb-job-data__field--' . esc_attr( str_replace( '_', '-', $field['xml_field'] ) ) . '" data-type="meta"><span class="label">' . esc_html( $field['name'] ) . ':</span> <span class="value">' . $value_prefix . $field_value . '</span></div>';
} // End foreach().
} // End if().
// add the meta output to the total output if we have meta output.
if ( '' !== $meta_output ) {
$output .= $meta_output;
}
// handle the job taxonomy terms first checking we have any.
if ( ! empty( $args['taxonomies'] ) ) {
// loop through each taxonomy.
foreach ( $args['taxonomies'] as $tax ) {
// if we are not showing on the front end.
if ( false === $tax['show_on_frontend'] ) {
continue;
}
// get the terms of this post.
$terms = wp_strip_all_tags(
get_the_term_list(
$args['post_id'],
$tax['taxonomy_name'],
'',
', ',
''
)
);
// if we have terms to display.
if ( '' !== $terms ) {
// add this to the tax output.
$tax_output .= '<div class="wpbb-job-data__field wpbb-job-data__field--' . esc_attr( str_replace( '_', '-', $tax['slug'] ) ) . '" data-type="term"><span class="label">' . esc_html( $tax['plural'] ) . ':</span> <span class="value">' . $terms . '</span></div>';
}
} // End foreach().
} // End if().
// add the meta output to the total output if we have meta output.
if ( '' !== $tax_output ) {
$output .= $tax_output;
}
// if we have output.
if ( '' !== $output ) {
// return output filtered.
return apply_filters( 'wpbb_get_job_meta_data', $output . '</div></div>', $args );
}
return '';
}September 26, 2019 at 10:04 am #493729Brad DaltonParticipantWhat's the name of the plugin?
What archive page type?
You can try something like this in a archive.php template or with the is_archive(); conditional tag in your child themes functions file :
add_action( 'genesis_after_entry_content', 'your_plugin_tag' ); function your_plugin_tag() { echo your_function(); }
Where your_function(); is the plugin function you want to output.
September 26, 2019 at 11:05 am #493730PhilMurrayParticipanthi Brad
plugin is called WP Broadbean
archive page is here - for a category called ACTIVE VACANCIES
https://llcc-ireland.fdmserver.com/job-industry/active-vacancies/
the plugin seems to generate the /job-industry/ label which is then followed by the category name in the URL
thanks
Phil
September 26, 2019 at 11:15 am #493731PhilMurrayParticipantThis reply has been marked as private.September 26, 2019 at 11:17 am #493732Brad DaltonParticipantI don't get private messages however you can contact me using [email protected]
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.