2024-01-09 16:13:20 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Functions which enhance the theme by hooking into WordPress
|
|
|
|
*
|
2024-01-13 15:46:11 +01:00
|
|
|
* @package Xarxaprod_theme
|
2024-01-09 16:13:20 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds custom classes to the array of body classes.
|
|
|
|
*
|
|
|
|
* @param array $classes Classes for the body element.
|
|
|
|
* @return array
|
|
|
|
*/
|
2024-01-13 15:46:11 +01:00
|
|
|
function xarxaprod_body_classes( $classes ) {
|
2024-01-09 16:13:20 +01:00
|
|
|
// Adds a class of hfeed to non-singular pages.
|
|
|
|
if ( ! is_singular() ) {
|
|
|
|
$classes[] = 'hfeed';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Adds a class of no-sidebar when there is no sidebar present.
|
|
|
|
if ( ! is_active_sidebar( 'sidebar-funds' ) ) {
|
|
|
|
$classes[] = 'no-sidebar';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $classes;
|
|
|
|
}
|
2024-01-13 15:46:11 +01:00
|
|
|
add_filter( 'body_class', 'xarxaprod_body_classes' );
|
2024-01-09 16:13:20 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a pingback url auto-discovery header for single posts, pages, or attachments.
|
|
|
|
*/
|
2024-01-13 15:46:11 +01:00
|
|
|
function xarxaprod_pingback_header() {
|
2024-01-09 16:13:20 +01:00
|
|
|
if ( is_singular() && pings_open() ) {
|
|
|
|
printf( '<link rel="pingback" href="%s">', esc_url( get_bloginfo( 'pingback_url' ) ) );
|
|
|
|
}
|
|
|
|
}
|
2024-01-13 15:46:11 +01:00
|
|
|
add_action( 'wp_head', 'xarxaprod_pingback_header' );
|
2024-01-09 16:13:20 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2024-01-13 15:46:11 +01:00
|
|
|
* Detect if the "xarxaprod" plugin is active
|
2024-01-09 16:13:20 +01:00
|
|
|
*/
|
|
|
|
|
2024-01-13 15:46:11 +01:00
|
|
|
function xarxaprod_plugin_active() {
|
2024-01-09 16:13:20 +01:00
|
|
|
// Detect plugin. For use on Front End only.
|
|
|
|
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
|
|
|
|
// check for plugin using plugin name
|
2024-01-13 15:46:11 +01:00
|
|
|
if ( is_plugin_active( 'xarxaprod-wp-plugin/xarxaprod-wp-plugin.php' ) ) {
|
2024-01-09 16:13:20 +01:00
|
|
|
//plugin is activated do
|
|
|
|
}
|
|
|
|
//do stuff here
|
|
|
|
} //closing if is_plugin_active
|
|
|
|
|
2024-01-13 15:46:11 +01:00
|
|
|
//add_action( 'wp_head', 'xarxaprod_plugin_active' );
|
2024-01-09 16:13:20 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Echo the post type slug
|
|
|
|
*/
|
2024-03-11 13:25:20 +01:00
|
|
|
if ( ! function_exists( 'xarxaprod_class_posttype' ) ):
|
|
|
|
function xarxaprod_class_posttype (){
|
|
|
|
if( is_post_type_archive( array('xarxaprod-ajut') ) || is_post_type_archive( array('xarxaprod-convo') ) || is_post_type_archive( array( 'xarxaprod-associat') )) {
|
|
|
|
//if( get_post_type() == 'xarxaprod-ajut' || get_post_type() == 'xarxaprod-convo' || get_post_type() == 'xarxaprod-associat' ){
|
|
|
|
echo 'archive-custom-post-type-';
|
|
|
|
printf (get_post_type_object( get_post_type() )->rewrite['slug']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
endif; //end xarxaprod_calss_posttype
|
|
|
|
|
|
|
|
|
2024-01-13 13:44:31 +01:00
|
|
|
/**
|
2024-01-13 13:30:18 +01:00
|
|
|
* Displays the FAQS subcategories from category id=1
|
2024-01-13 13:44:31 +01:00
|
|
|
*/
|
|
|
|
|
2024-01-13 15:46:11 +01:00
|
|
|
if ( ! function_exists( 'xarxaprod_display_faqs_labels' ) ) :
|
|
|
|
function xarxaprod_display_faqs_labels() {
|
2024-01-13 13:44:31 +01:00
|
|
|
?>
|
2024-01-13 15:46:11 +01:00
|
|
|
<nav id="tipus-faqs" class="xarxaprod-faqs-types">
|
|
|
|
<ul class="xarxaprod-label">
|
2024-01-13 13:30:18 +01:00
|
|
|
<?php
|
|
|
|
// https://developer.wordpress.org/reference%2Ffunctions%2Fwp_list_categories%2F/
|
|
|
|
wp_list_categories(
|
|
|
|
array(
|
2024-01-14 20:13:11 +01:00
|
|
|
'child_of' => 38, // category FAQ id=1
|
2024-01-13 13:30:18 +01:00
|
|
|
'hide_empty' => 1,
|
|
|
|
'hide_title_if_empty' => true,
|
|
|
|
'separator' => '<li>',
|
|
|
|
'style' => 'list',
|
|
|
|
'taxonomy' => 'category',
|
|
|
|
'title_li' => '',
|
|
|
|
)
|
|
|
|
); ?>
|
|
|
|
</ul>
|
|
|
|
</nav>
|
|
|
|
<?php
|
2024-01-13 13:44:31 +01:00
|
|
|
}
|
2024-01-13 15:46:11 +01:00
|
|
|
endif; //end xarxaprod_display_faqs_labels
|
2024-01-13 13:44:31 +01:00
|
|
|
|
|
|
|
/**
|
2024-01-13 13:30:18 +01:00
|
|
|
* Displays categories for each FAQ
|
2024-01-13 13:44:31 +01:00
|
|
|
*/
|
|
|
|
|
2024-01-13 15:46:11 +01:00
|
|
|
if ( ! function_exists( 'xarxaprod_display_each_faq_categories' ) ) :
|
|
|
|
function xarxaprod_display_each_faq_categories() {
|
2024-01-13 13:44:31 +01:00
|
|
|
|
2024-01-13 13:30:18 +01:00
|
|
|
$categories = get_the_category();
|
|
|
|
if ( ! empty( $categories ) ) {
|
2024-01-13 15:46:11 +01:00
|
|
|
echo ' <nav id="tipus-faqs" class="xarxaprod-faqs-types">';
|
|
|
|
echo ' <ul class="xarxaprod-label">';
|
2024-01-13 13:30:18 +01:00
|
|
|
foreach ( $categories as $category ) {
|
|
|
|
if ( ! ($category->cat_ID == '1') ) { //cat_ID '1' is defined as default FAQ
|
|
|
|
echo '<li class="cat-item"><a href="' . esc_url( get_category_link( $category->term_id ) ) . '">' . esc_html( $category->name ) . '</a></li>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
echo ' </ul>';
|
|
|
|
echo ' </nav>';
|
|
|
|
}
|
2024-01-13 13:44:31 +01:00
|
|
|
}
|
2024-01-13 15:46:11 +01:00
|
|
|
endif; //end xarxaprod_display_each_faq_categories
|
2024-01-13 13:44:31 +01:00
|
|
|
|
|
|
|
/**
|
2024-01-13 13:30:18 +01:00
|
|
|
* Display search form for FAQs
|
2024-01-13 13:44:31 +01:00
|
|
|
*/
|
|
|
|
|
2024-01-13 15:46:11 +01:00
|
|
|
if ( ! function_exists( 'xarxaprod_display_faq_search' ) ) :
|
|
|
|
function xarxaprod_display_faqs_search() {
|
2024-01-13 13:30:18 +01:00
|
|
|
// search form for category
|
|
|
|
// https://developer.wordpress.org/reference/functions/get_search_form/#comment-369
|
|
|
|
// https://wordpress.stackexchange.com/questions/313037/restrict-a-search-to-a-custom-post-type
|
2024-01-13 13:44:31 +01:00
|
|
|
?>
|
2024-01-13 15:46:11 +01:00
|
|
|
<form class="xarxaprod-search-form" role="search" method="get" action="/">
|
2024-01-13 13:30:18 +01:00
|
|
|
<label class="screen-reader-text" for="search">Search in ajuts</label>
|
|
|
|
<input type="search" id="search" class="search-field" placeholder="cerca faqs..." value="<?php the_search_query();?>" name="s" />
|
|
|
|
<input type="submit" id="searchsubmit" class="search-submit button button-search" value="cerca">
|
2024-01-13 15:46:11 +01:00
|
|
|
<span class="xarxaprod-search-submit xarxaprod-icon-search"></span>
|
2024-01-13 13:30:18 +01:00
|
|
|
<input type="hidden" value="posts" name="post_type" id="post_type" />
|
|
|
|
<input type="hidden" value="faq" name="category_name" id="category_name" />
|
|
|
|
</form>
|
|
|
|
<?php
|
|
|
|
}
|
2024-01-13 15:46:11 +01:00
|
|
|
endif; //end xarxaprod_display_each_faq_categories
|