Se movió el repositorio git desde la raíz de WordPress a la carpeta del tema. Este commit limpia todos los archivos de WordPress del historial de tracking y mantiene únicamente los archivos del tema apus-theme. Cambios: - Eliminado tracking de archivos de WordPress core - Mantenido solo archivos del tema (97 archivos) - Actualizado .gitignore para excluir carpetas de desarrollo - Historial de commits anteriores se mantiene intacto 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
273 lines
10 KiB
PHP
273 lines
10 KiB
PHP
<?php
|
|
/**
|
|
* Related Posts Configuration Options
|
|
*
|
|
* This file provides helper functions and documentation for configuring
|
|
* related posts functionality via WordPress options.
|
|
*
|
|
* @package Apus_Theme
|
|
* @since 1.0.0
|
|
*/
|
|
|
|
// Exit if accessed directly
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* Get all related posts options with their current values
|
|
*
|
|
* @return array Array of options with their values
|
|
*/
|
|
function apus_get_related_posts_options() {
|
|
return array(
|
|
'enabled' => array(
|
|
'key' => 'apus_related_posts_enabled',
|
|
'value' => get_option('apus_related_posts_enabled', true),
|
|
'type' => 'boolean',
|
|
'default' => true,
|
|
'label' => __('Enable Related Posts', 'apus-theme'),
|
|
'description' => __('Show related posts section at the end of single posts', 'apus-theme'),
|
|
),
|
|
'title' => array(
|
|
'key' => 'apus_related_posts_title',
|
|
'value' => get_option('apus_related_posts_title', __('Related Posts', 'apus-theme')),
|
|
'type' => 'text',
|
|
'default' => __('Related Posts', 'apus-theme'),
|
|
'label' => __('Section Title', 'apus-theme'),
|
|
'description' => __('Title displayed above related posts', 'apus-theme'),
|
|
),
|
|
'count' => array(
|
|
'key' => 'apus_related_posts_count',
|
|
'value' => get_option('apus_related_posts_count', 3),
|
|
'type' => 'number',
|
|
'default' => 3,
|
|
'min' => 1,
|
|
'max' => 12,
|
|
'label' => __('Number of Posts', 'apus-theme'),
|
|
'description' => __('Maximum number of related posts to display', 'apus-theme'),
|
|
),
|
|
'columns' => array(
|
|
'key' => 'apus_related_posts_columns',
|
|
'value' => get_option('apus_related_posts_columns', 3),
|
|
'type' => 'select',
|
|
'default' => 3,
|
|
'options' => array(
|
|
1 => __('1 Column', 'apus-theme'),
|
|
2 => __('2 Columns', 'apus-theme'),
|
|
3 => __('3 Columns', 'apus-theme'),
|
|
4 => __('4 Columns', 'apus-theme'),
|
|
),
|
|
'label' => __('Grid Columns', 'apus-theme'),
|
|
'description' => __('Number of columns in the grid layout (responsive)', 'apus-theme'),
|
|
),
|
|
'show_excerpt' => array(
|
|
'key' => 'apus_related_posts_show_excerpt',
|
|
'value' => get_option('apus_related_posts_show_excerpt', true),
|
|
'type' => 'boolean',
|
|
'default' => true,
|
|
'label' => __('Show Excerpt', 'apus-theme'),
|
|
'description' => __('Display post excerpt in related posts cards', 'apus-theme'),
|
|
),
|
|
'excerpt_length' => array(
|
|
'key' => 'apus_related_posts_excerpt_length',
|
|
'value' => get_option('apus_related_posts_excerpt_length', 20),
|
|
'type' => 'number',
|
|
'default' => 20,
|
|
'min' => 5,
|
|
'max' => 100,
|
|
'label' => __('Excerpt Length', 'apus-theme'),
|
|
'description' => __('Number of words in the excerpt', 'apus-theme'),
|
|
),
|
|
'show_date' => array(
|
|
'key' => 'apus_related_posts_show_date',
|
|
'value' => get_option('apus_related_posts_show_date', true),
|
|
'type' => 'boolean',
|
|
'default' => true,
|
|
'label' => __('Show Date', 'apus-theme'),
|
|
'description' => __('Display publication date in related posts', 'apus-theme'),
|
|
),
|
|
'show_category' => array(
|
|
'key' => 'apus_related_posts_show_category',
|
|
'value' => get_option('apus_related_posts_show_category', true),
|
|
'type' => 'boolean',
|
|
'default' => true,
|
|
'label' => __('Show Category', 'apus-theme'),
|
|
'description' => __('Display category badge on related posts', 'apus-theme'),
|
|
),
|
|
'bg_colors' => array(
|
|
'key' => 'apus_related_posts_bg_colors',
|
|
'value' => get_option('apus_related_posts_bg_colors', array(
|
|
'#1a73e8', '#e91e63', '#4caf50', '#ff9800', '#9c27b0', '#00bcd4',
|
|
)),
|
|
'type' => 'color_array',
|
|
'default' => array(
|
|
'#1a73e8', // Blue
|
|
'#e91e63', // Pink
|
|
'#4caf50', // Green
|
|
'#ff9800', // Orange
|
|
'#9c27b0', // Purple
|
|
'#00bcd4', // Cyan
|
|
),
|
|
'label' => __('Background Colors', 'apus-theme'),
|
|
'description' => __('Colors used for posts without featured images', 'apus-theme'),
|
|
),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Update a related posts option
|
|
*
|
|
* @param string $option_key The option key (without 'apus_related_posts_' prefix)
|
|
* @param mixed $value The new value
|
|
* @return bool True if updated successfully
|
|
*/
|
|
function apus_update_related_posts_option($option_key, $value) {
|
|
$full_key = 'apus_related_posts_' . $option_key;
|
|
return update_option($full_key, $value);
|
|
}
|
|
|
|
/**
|
|
* Reset related posts options to defaults
|
|
*
|
|
* @return bool True if reset successfully
|
|
*/
|
|
function apus_reset_related_posts_options() {
|
|
$options = apus_get_related_posts_options();
|
|
$success = true;
|
|
|
|
foreach ($options as $option) {
|
|
if (!update_option($option['key'], $option['default'])) {
|
|
$success = false;
|
|
}
|
|
}
|
|
|
|
return $success;
|
|
}
|
|
|
|
/**
|
|
* Example: Programmatically configure related posts
|
|
*
|
|
* This function shows how to configure related posts options programmatically.
|
|
* You can call this from your functions.php or a plugin.
|
|
*
|
|
* @return void
|
|
*/
|
|
function apus_example_configure_related_posts() {
|
|
// Example usage - uncomment to use:
|
|
|
|
// Enable related posts
|
|
// update_option('apus_related_posts_enabled', true);
|
|
|
|
// Set custom title
|
|
// update_option('apus_related_posts_title', __('You Might Also Like', 'apus-theme'));
|
|
|
|
// Show 4 related posts
|
|
// update_option('apus_related_posts_count', 4);
|
|
|
|
// Use 2 columns layout
|
|
// update_option('apus_related_posts_columns', 2);
|
|
|
|
// Show excerpt with 30 words
|
|
// update_option('apus_related_posts_show_excerpt', true);
|
|
// update_option('apus_related_posts_excerpt_length', 30);
|
|
|
|
// Show date and category
|
|
// update_option('apus_related_posts_show_date', true);
|
|
// update_option('apus_related_posts_show_category', true);
|
|
|
|
// Custom background colors for posts without images
|
|
// update_option('apus_related_posts_bg_colors', array(
|
|
// '#FF6B6B', // Red
|
|
// '#4ECDC4', // Teal
|
|
// '#45B7D1', // Blue
|
|
// '#FFA07A', // Coral
|
|
// '#98D8C8', // Mint
|
|
// '#F7DC6F', // Yellow
|
|
// ));
|
|
}
|
|
|
|
/**
|
|
* Filter hook example: Modify related posts query
|
|
*
|
|
* This example shows how to customize the related posts query.
|
|
* Add this to your functions.php or child theme.
|
|
*/
|
|
function apus_example_modify_related_posts_query($args, $post_id) {
|
|
// Example: Order by date instead of random
|
|
// $args['orderby'] = 'date';
|
|
// $args['order'] = 'DESC';
|
|
|
|
// Example: Only show posts from the last 6 months
|
|
// $args['date_query'] = array(
|
|
// array(
|
|
// 'after' => '6 months ago',
|
|
// ),
|
|
// );
|
|
|
|
// Example: Exclude specific category
|
|
// $args['category__not_in'] = array(5); // Replace 5 with category ID
|
|
|
|
return $args;
|
|
}
|
|
// add_filter('apus_related_posts_args', 'apus_example_modify_related_posts_query', 10, 2);
|
|
|
|
/**
|
|
* Get documentation for related posts configuration
|
|
*
|
|
* @return array Documentation array
|
|
*/
|
|
function apus_get_related_posts_documentation() {
|
|
return array(
|
|
'overview' => array(
|
|
'title' => __('Related Posts Overview', 'apus-theme'),
|
|
'content' => __(
|
|
'The related posts feature automatically displays relevant posts at the end of each blog post. ' .
|
|
'Posts are related based on shared categories and displayed in a responsive Bootstrap grid.',
|
|
'apus-theme'
|
|
),
|
|
),
|
|
'features' => array(
|
|
'title' => __('Key Features', 'apus-theme'),
|
|
'items' => array(
|
|
__('Automatic category-based matching', 'apus-theme'),
|
|
__('Responsive Bootstrap 5 grid layout', 'apus-theme'),
|
|
__('Configurable number of posts and columns', 'apus-theme'),
|
|
__('Support for posts with and without featured images', 'apus-theme'),
|
|
__('Beautiful color backgrounds for posts without images', 'apus-theme'),
|
|
__('Customizable excerpt length', 'apus-theme'),
|
|
__('Optional display of dates and categories', 'apus-theme'),
|
|
__('Smooth hover animations', 'apus-theme'),
|
|
__('Print-friendly styles', 'apus-theme'),
|
|
__('Dark mode support', 'apus-theme'),
|
|
),
|
|
),
|
|
'configuration' => array(
|
|
'title' => __('How to Configure', 'apus-theme'),
|
|
'methods' => array(
|
|
'database' => array(
|
|
'title' => __('Via WordPress Options API', 'apus-theme'),
|
|
'code' => "update_option('apus_related_posts_enabled', true);\nupdate_option('apus_related_posts_count', 4);",
|
|
),
|
|
'filter' => array(
|
|
'title' => __('Via Filter Hook', 'apus-theme'),
|
|
'code' => "add_filter('apus_related_posts_args', function(\$args, \$post_id) {\n \$args['posts_per_page'] = 6;\n return \$args;\n}, 10, 2);",
|
|
),
|
|
),
|
|
),
|
|
'customization' => array(
|
|
'title' => __('Customization Examples', 'apus-theme'),
|
|
'examples' => array(
|
|
array(
|
|
'title' => __('Change title and layout', 'apus-theme'),
|
|
'code' => "update_option('apus_related_posts_title', 'También te puede interesar');\nupdate_option('apus_related_posts_columns', 4);",
|
|
),
|
|
array(
|
|
'title' => __('Customize colors', 'apus-theme'),
|
|
'code' => "update_option('apus_related_posts_bg_colors', array(\n '#FF6B6B',\n '#4ECDC4',\n '#45B7D1'\n));",
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|