';
}
// Limit Post
function the_content_limit($max_char, $more_link_text = '', $stripteaser = 0, $more_file = '') {
$content = get_the_content($more_link_text, $stripteaser, $more_file);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
$content = strip_tags($content);
if (strlen($_GET['p']) > 0) {
echo "";
echo $content;
echo " "."";
echo "";
}
else if ((strlen($content)>$max_char) && ($espacio = strpos($content, " ", $max_char ))) {
$content = substr($content, 0, $espacio);
$content = $content;
echo "";
echo $content;
echo " "."";
echo "";
}
else {
echo "";
echo $content;
echo " "."";
echo "";
}
}
// Custom post type
add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'testimonials',
array(
'labels' => array(
'name' => 'Testimonials',
'singular_name' => 'Testimonial',
'add_new' => 'Add New',
'add_new_item' => 'Add New Testimonial',
'edit_item' => 'Edit Testimonial',
'new_item' => 'New Testimonial',
'all_items' => 'All Testimonials',
'view_item' => 'View Testimonial Item',
'search_items' => 'Search Testimonial Item',
'not_found' => 'No Testimonials Found',
'not_found_in_trash' => 'No Testimonials Found in the Trash',
'parent_item_colon' => '',
'menu_name' => 'Testimonials'
),
'public' => true,
'has_archive' => true,
'taxonomies' => array('', ''), // this is IMPORTANT
'supports' => array('title', 'thumbnail', 'custom-fields', 'page-attributes', 'editor')
)
);
}
// Retrieves the setting's value depending on 'key'.
function theme_settings($key) {
global $settings;
return $settings[$key];
}
// Custom Menu Order
function custom_menu_order($menu_ord) {
if (!$menu_ord) return true;
return array(
'index.php', // Dashboard
'separator1', // First separator
'edit.php', // Posts
'edit.php?post_type=page', // Pages
'edit.php?post_type=testimonials', // Services
'upload.php', // Media
'link-manager.php', // Links
'edit-comments.php', // Comments
'separator2', // Second separator
'themes.php', // Appearance
'plugins.php', // Plugins
'users.php', // Users
'tools.php', // Tools
'options-general.php', // Settings
'separator-last', // Last separator
);
}
add_filter('custom_menu_order', 'custom_menu_order'); // Activate custom_menu_order
add_filter('menu_order', 'custom_menu_order');
// I want a favicon in the dashboard area
function ni_favicon() {
echo '';
}
add_action('admin_head','ni_favicon');
// featured image
add_theme_support( 'post-thumbnails' );
// shortcode for list of pages
add_shortcode('sitemap', 'wp_sitemap_page');
function wp_sitemap_page(){
return "
".wp_list_pages('title_li=&echo=0')."
";
}
// Internal link builder
function auto_add_internal_links($content) {
global $post;
// Ensure we are working with a valid post object
if (!isset($post->ID)) {
return $content;
}
// Check if the post has the 'page_generator' meta key
if (!get_post_meta($post->ID, '_page_generator_pro_index', true)) {
return $content; // Return original content if the meta key is missing
}
// Check if internal links already exist for this post
$existing_links = get_post_meta($post->ID, '_internal_links', true);
// If not set, generate and store them
if (!$existing_links) {
$args = array(
'post_type' => 'page',
'posts_per_page' => 5, // Adjust as needed
'post__not_in' => array($post->ID), // Exclude current page
'orderby' => 'rand'
);
$query = new WP_Query($args);
if ($query->have_posts()) {
$internal_links = '
More Like This:
';
while ($query->have_posts()) {
$query->the_post();
$internal_links .= '
';
wp_reset_postdata();
// Store links in post meta so they don't change every time
update_post_meta($post->ID, '_internal_links', $internal_links);
}
} else {
$internal_links = $existing_links;
}
return $content . $internal_links;
}
// Hook into content filter
add_filter('the_content', 'auto_add_internal_links');
?>