xarxaprod-wp-theme/inc/template-functions.php

137 lines
4.3 KiB
PHP
Raw Permalink Normal View History

2024-01-09 16:13:20 +01:00
<?php
/**
* Functions which enhance the theme by hooking into WordPress
*
* @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
*/
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;
}
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.
*/
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' ) ) );
}
}
add_action( 'wp_head', 'xarxaprod_pingback_header' );
2024-01-09 16:13:20 +01:00
/**
* Detect if the "xarxaprod" plugin is active
2024-01-09 16:13:20 +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
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
//add_action( 'wp_head', 'xarxaprod_plugin_active' );
2024-01-09 16:13:20 +01:00
/**
* Echo the post type slug
*/
function xarxaprod_class_posttype (){
if( is_post_type_archive( array('xarxaprod-ajut') )) {
2024-01-09 16:13:20 +01:00
echo 'archive-custom-post-type-';
printf(get_post_type_object( get_post_type() )->rewrite['slug'] );
}
}
/**
2024-01-13 13:30:18 +01:00
* Displays the FAQS subcategories from category id=1
*/
if ( ! function_exists( 'xarxaprod_display_faqs_labels' ) ) :
function xarxaprod_display_faqs_labels() {
?>
<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(
'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
}
endif; //end xarxaprod_display_faqs_labels
/**
2024-01-13 13:30:18 +01:00
* Displays categories for each FAQ
*/
if ( ! function_exists( 'xarxaprod_display_each_faq_categories' ) ) :
function xarxaprod_display_each_faq_categories() {
2024-01-13 13:30:18 +01:00
$categories = get_the_category();
if ( ! empty( $categories ) ) {
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>';
}
}
endif; //end xarxaprod_display_each_faq_categories
/**
2024-01-13 13:30:18 +01:00
* Display search form for FAQs
*/
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
?>
<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">
<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
}
endif; //end xarxaprod_display_each_faq_categories