array( 'key' => 'roi_related_posts_enabled', 'value' => get_option('roi_related_posts_enabled', true), 'type' => 'boolean', 'default' => true, 'label' => __('Enable Related Posts', 'roi-theme'), 'description' => __('Show related posts section at the end of single posts', 'roi-theme'), ), 'title' => array( 'key' => 'roi_related_posts_title', 'value' => get_option('roi_related_posts_title', __('Related Posts', 'roi-theme')), 'type' => 'text', 'default' => __('Related Posts', 'roi-theme'), 'label' => __('Section Title', 'roi-theme'), 'description' => __('Title displayed above related posts', 'roi-theme'), ), 'count' => array( 'key' => 'roi_related_posts_count', 'value' => get_option('roi_related_posts_count', 3), 'type' => 'number', 'default' => 3, 'min' => 1, 'max' => 12, 'label' => __('Number of Posts', 'roi-theme'), 'description' => __('Maximum number of related posts to display', 'roi-theme'), ), 'columns' => array( 'key' => 'roi_related_posts_columns', 'value' => get_option('roi_related_posts_columns', 3), 'type' => 'select', 'default' => 3, 'options' => array( 1 => __('1 Column', 'roi-theme'), 2 => __('2 Columns', 'roi-theme'), 3 => __('3 Columns', 'roi-theme'), 4 => __('4 Columns', 'roi-theme'), ), 'label' => __('Grid Columns', 'roi-theme'), 'description' => __('Number of columns in the grid layout (responsive)', 'roi-theme'), ), 'show_excerpt' => array( 'key' => 'roi_related_posts_show_excerpt', 'value' => get_option('roi_related_posts_show_excerpt', true), 'type' => 'boolean', 'default' => true, 'label' => __('Show Excerpt', 'roi-theme'), 'description' => __('Display post excerpt in related posts cards', 'roi-theme'), ), 'excerpt_length' => array( 'key' => 'roi_related_posts_excerpt_length', 'value' => get_option('roi_related_posts_excerpt_length', 20), 'type' => 'number', 'default' => 20, 'min' => 5, 'max' => 100, 'label' => __('Excerpt Length', 'roi-theme'), 'description' => __('Number of words in the excerpt', 'roi-theme'), ), 'show_date' => array( 'key' => 'roi_related_posts_show_date', 'value' => get_option('roi_related_posts_show_date', true), 'type' => 'boolean', 'default' => true, 'label' => __('Show Date', 'roi-theme'), 'description' => __('Display publication date in related posts', 'roi-theme'), ), 'show_category' => array( 'key' => 'roi_related_posts_show_category', 'value' => get_option('roi_related_posts_show_category', true), 'type' => 'boolean', 'default' => true, 'label' => __('Show Category', 'roi-theme'), 'description' => __('Display category badge on related posts', 'roi-theme'), ), 'bg_colors' => array( 'key' => 'roi_related_posts_bg_colors', 'value' => get_option('roi_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', 'roi-theme'), 'description' => __('Colors used for posts without featured images', 'roi-theme'), ), ); } /** * Update a related posts option * * @param string $option_key The option key (without 'roi_related_posts_' prefix) * @param mixed $value The new value * @return bool True if updated successfully */ function roi_update_related_posts_option($option_key, $value) { $full_key = 'roi_related_posts_' . $option_key; return update_option($full_key, $value); } /** * Reset related posts options to defaults * * @return bool True if reset successfully */ function roi_reset_related_posts_options() { $options = roi_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 roi_example_configure_related_posts() { // Example usage - uncomment to use: // Enable related posts // update_option('roi_related_posts_enabled', true); // Set custom title // update_option('roi_related_posts_title', __('You Might Also Like', 'roi-theme')); // Show 4 related posts // update_option('roi_related_posts_count', 4); // Use 2 columns layout // update_option('roi_related_posts_columns', 2); // Show excerpt with 30 words // update_option('roi_related_posts_show_excerpt', true); // update_option('roi_related_posts_excerpt_length', 30); // Show date and category // update_option('roi_related_posts_show_date', true); // update_option('roi_related_posts_show_category', true); // Custom background colors for posts without images // update_option('roi_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 roi_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('roi_related_posts_args', 'roi_example_modify_related_posts_query', 10, 2); /** * Get documentation for related posts configuration * * @return array Documentation array */ function roi_get_related_posts_documentation() { return array( 'overview' => array( 'title' => __('Related Posts Overview', 'roi-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.', 'roi-theme' ), ), 'features' => array( 'title' => __('Key Features', 'roi-theme'), 'items' => array( __('Automatic category-based matching', 'roi-theme'), __('Responsive Bootstrap 5 grid layout', 'roi-theme'), __('Configurable number of posts and columns', 'roi-theme'), __('Support for posts with and without featured images', 'roi-theme'), __('Beautiful color backgrounds for posts without images', 'roi-theme'), __('Customizable excerpt length', 'roi-theme'), __('Optional display of dates and categories', 'roi-theme'), __('Smooth hover animations', 'roi-theme'), __('Print-friendly styles', 'roi-theme'), __('Dark mode support', 'roi-theme'), ), ), 'configuration' => array( 'title' => __('How to Configure', 'roi-theme'), 'methods' => array( 'database' => array( 'title' => __('Via WordPress Options API', 'roi-theme'), 'code' => "update_option('roi_related_posts_enabled', true);\nupdate_option('roi_related_posts_count', 4);", ), 'filter' => array( 'title' => __('Via Filter Hook', 'roi-theme'), 'code' => "add_filter('roi_related_posts_args', function(\$args, \$post_id) {\n \$args['posts_per_page'] = 6;\n return \$args;\n}, 10, 2);", ), ), ), 'customization' => array( 'title' => __('Customization Examples', 'roi-theme'), 'examples' => array( array( 'title' => __('Change title and layout', 'roi-theme'), 'code' => "update_option('roi_related_posts_title', 'TambiƩn te puede interesar');\nupdate_option('roi_related_posts_columns', 4);", ), array( 'title' => __('Customize colors', 'roi-theme'), 'code' => "update_option('roi_related_posts_bg_colors', array(\n '#FF6B6B',\n '#4ECDC4',\n '#45B7D1'\n));", ), ), ), ); }