Increasing Limit of Silo Navigation Widget

CrushL

Junior Member
Joined
Jul 4, 2013
Messages
160
Reaction score
46
Hello,

I'm currently experimenting with different silo themes and plugins and have a problem with a little plugin that creates silo navigation on a widget. The problem is: It only shows a maximum of 10 entrys in its navigation ("Home" + 9 Silos). I guess there should be an entry somewhere in that code for the maximum number, but I'm really not good in coding so I figured I ask you guys on here. I tried to change some array numbers from 10 to 20, but with no effect (numbers i changed are located at the bottom of the first part, but for this post I set everything back to default). So here is the code of the plugin (split in 2 files):

Plugin Code

Code:
<?php/*
Plugin Name: WpSilos2
Description: SEO Interlinking Silo Plugin
Version: 1.0
Author:Abbas Ravji
Author URI: www.wpsilos.com
*/
global $wpdb;
define( "INTERLINKS_URL", untrailingslashit( plugins_url( '/', __FILE__ ) ) );
define( "INTERLINKS_PATH", untrailingslashit( plugin_dir_path( __FILE__ ) ) );
//define( "INTERLINKS_TABLE", $wpdb->prefix. "faqs");
class InterLinksManager {
    
    function admin_enqueue(){
        wp_register_style('interlinks-css', INTERLINKS_URL . '/style.css');
        wp_enqueue_style('interlinks-css');
    }
    /** post / page **/
    function save_post($post_id){
        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
        
        if ( isset($_POST['interlink_interlinks']) ) {
            if( ! wp_verify_nonce( $_POST['interlink_interlinks'], 'interlink_interlinks_nonce' ) ) {
                wp_die( __( 'Cheatin' uh?' ) );
            }
            
            global $post;
            if ( empty( $post ) ) { $post = get_post( $post_id ); }
            
            $interlink_category = $_POST['interlink_category'];
            
            if ( $interlink_category != "no-category" ) {
                if ( $interlink_category == "add-new" ) {
                    // add manual category to page 
                    $term_name = $post->post_title;
                    $term = term_exists( $term_name, 'category' );
                    if ($term !== 0 && $term !== null) { // page title have same category term 
                        $interlink_category = $term['term_id'];
                    } else { // page title does not exists in category terms, add new 
                        $interlink_category = wp_insert_term( $term_name, 'category' );
                        if ( !is_wp_error( $interlink_category ) ) {
                            $interlink_category = $interlink_category['term_id'];
                        }
                    }
                }
                // update interlink_category for the page 
                update_post_meta($post_id, "interlink_category", $interlink_category);
                // update interlink_page for the category 
                $interlink_page = get_option( $interlink_category . "_interlink_page" );
                if ( $interlink_page ) { // exists for the category
                    update_option($interlink_category . "_interlink_page", $post_id);
                } else { // does not exists for the category
                    update_option($interlink_category . "_interlink_page", $post_id);
                }
            } else {
                delete_post_meta($post_id, "interlink_category");
            }
        }    
    }
    
    function interlinks_form($post){
        wp_nonce_field( 'interlink_interlinks_nonce', 'interlink_interlinks', TRUE, TRUE );
        $interlink_category = get_post_meta($post->ID, "interlink_category", TRUE);
        $categories = get_categories(array(
            'hide_empty' => FALSE,
        ));
        ?>
        <label for='interlink_category'>Interlink Category</label>
        <select name='interlink_category' id='interlink_category'>
            <option value='add-new'>Add New</option>
            <option value='no-category'>No Interlink Category</option>
            <?php
            foreach($categories as $category) {
                $sel = $category->term_id == $interlink_category ? 'selected="selected"' : NULL;
                echo "<option value='{$category->term_id}' {$sel}>{$category->name}</option>"; 
            }
            ?>
        </select>
        <?php
    }
     
    function interlinks_meta_box() {
        /*
        add_meta_box(
            'interlinks_boxid',
            'Category',
            array('InterLinksManager', 'interlinks_form'),
            'post',
            'side'
        );
        */
        add_meta_box(
            'interlinks_boxid',
            'Interlink Category',
            array('InterLinksManager', 'interlinks_form'),
            'page',
            'side'
        );
    }
    
    function interlinks_type_columns( $defaults ) {
        $defaults['interlink-category'] = 'Interlink Category';
        return $defaults;
    }
    
    function interlinks_type_custom_column($column_name, $post_id){
        if ( $column_name == 'interlink-category') {
            $interlink_category = get_post_meta( $post_id, "interlink_category", TRUE);
            if ( $interlink_category && $interlink_category != "" ) {
                $term = get_term( $interlink_category, 'category' );
                if ($term) {
                    echo $term->name;
                }
            }
        }
    }
    /** category **/
    function add_category_fields($taxonomy){
        ?>
        <div class="form-field">
            <label for="interlink_page">Interlink Page</label>
            <?php
            $args = array(
                'echo' => 1,
                'name' => 'interlink_page'
            );
            wp_dropdown_pages( $args )
            ?>
            <?php wp_nonce_field( 'interlink_interlinks_nonce', 'interlink_interlinks', TRUE, TRUE );?>
            <p class="description">Interlink Assigned Page</p>
        </div>
        <?php
    }


    function edit_category_fields($taxonomy){
        ?>
        <tr class="form-field">
            <th valign="top" scope="row"><label for="interlink_page">Interlink Page</label></th>
            <td>
                <?php
                $interlink_page = get_option( $taxonomy->term_id . "_interlink_page" );
                $args = array(
                    'echo' => 1,
                    'selected' => $interlink_page,
                    'name' => 'interlink_page'
                );
                wp_dropdown_pages( $args )
                ?>
                <?php wp_nonce_field( 'interlink_interlinks_nonce', 'interlink_interlinks', TRUE, TRUE );?>
                <p class="description">Interlink Assigned Page</p>
            </td>
        </tr>
        <?php
    }


    function save_category_fields( $cat_id ) {
        if ( isset($_POST['interlink_interlinks']) ) {
            if( ! wp_verify_nonce( $_POST['interlink_interlinks'], 'interlink_interlinks_nonce' ) ) {
                wp_die( __( 'Cheatin' uh?' ) );
            }
            // update assigned page here
            update_option( $cat_id."_interlink_page", $_POST['interlink_page'] );
            // update page according to category
            update_post_meta( $_POST['interlink_page'], "interlink_category", $cat_id);
        }
    }
     
    function interlinks_settings_func(){
        if ( isset($_POST['interlink_interlinks']) ) {
            if( ! wp_verify_nonce( $_POST['interlink_interlinks'], 'interlink_interlinks_nonce' ) ) {
                wp_die( __( 'Cheatin' uh?' ) );
            }
            // save settings here
            update_option("interlinks_settings", $_POST['interlinks_settings']);
            echo '<div id="message" class="updated fade"><p><strong>InterLinks Settings updated successfully.</strong></p></div>';
        }
        $interlinks_settings = get_option("interlinks_settings", TRUE);
        ?>
                <style>
                    .ads img{
                    
                        border:0;
                        text-decoration: none;
                    }
                    
                </style>
        <div class='wrap'>
                    <div style="float:left; width:70%">
            <div class="icon32" id="icon-link-manager"></div>
            <h2>InterLinks Settings</h2>
            <form action="options-general.php?page=interlinks-settings" method="post">
                <?php wp_nonce_field( 'interlink_interlinks_nonce', 'interlink_interlinks', TRUE, TRUE ); ?>
                <p style="width: 300px;">
                    <label for='number_of_recent_posts'>Number of Recent Posts:</label>
                    <input class="widefat" id="number_of_recent_posts" name="interlinks_settings[number_of_recent_posts]" type="text" value="<?php if(isset($interlinks_settings["number_of_recent_posts"])) echo $interlinks_settings["number_of_recent_posts"]; ?>" />
                </p>
                                
                                <p style="width: 300px;">
                    <label for='number_of_recent_posts'>Number of Related Posts:</label>
                    <input class="widefat" id="number_of_recent_posts" name="interlinks_settings[number_of_related_posts]" type="text" value="<?php if(isset($interlinks_settings["number_of_related_posts"])) echo $interlinks_settings["number_of_related_posts"]; ?>" />
                </p>
                <p style="width: 300px;">
                    <label for='title_heading'>Title Heading:</label>
                    <select name="interlinks_settings[title_heading]" id="title_heading" class="widefat" >
                        <option value="<h1>|</h1>" <?php echo $interlinks_settings['title_heading'] == "<h1>|</h1>" ? 'selected="selected"' : NULL;?>>H1</option>
                        <option value="<h2>|</h2>" <?php echo $interlinks_settings['title_heading'] == "<h2>|</h2>" ? 'selected="selected"' : NULL;?>>H2</option>
                        <option value="<h3>|</h3>" <?php echo $interlinks_settings['title_heading'] == "<h3>|</h3>" ? 'selected="selected"' : NULL;?>>H3</option>
                        <option value="<h4>|</h4>" <?php echo $interlinks_settings['title_heading'] == "<h4>|</h4>" ? 'selected="selected"' : NULL;?>>H4</option>
                        <option value="<h5>|</h5>" <?php echo $interlinks_settings['title_heading'] == "<h5>|</h5>" ? 'selected="selected"' : NULL;?>>H5</option>
                        <option value="<h6>|</h6>" <?php echo $interlinks_settings['title_heading'] == "<h6>|</h6>" ? 'selected="selected"' : NULL;?>>H6</option>
                    </select>
                    
                    
                </p>
                <p style="width: 300px;">
                    <label for='home_title'>Home Title:</label>
                    <input class="widefat" id="home_title" name="interlinks_settings[home_title]" type="text" value="<?php if(isset($interlinks_settings['home_title'])) echo $interlinks_settings['home_title']; ?>" />
                </p>
                               <p style="width: 300px;">
                    <label for='pages_title'>Home Anchor Text:</label>
                    <input class="widefat" id="pages_title" name="interlinks_settings[pages_title]" type="text" value="<?php if(!isset($interlinks_settings['posts_title']) && $interlinks_settings['posts_title']=='') echo "Home";  else echo $interlinks_settings['pages_title']; ?>" />
                </p>
                
                                
                               
                <p style="width: 300px;">
                    <label for='category_title'>Related Post Title:</label>
                    <input class="widefat" id="category_title" name="interlinks_settings[related_title]" type="text" value="<?php if(isset($interlinks_settings['related_title'])) echo $interlinks_settings['related_title']; ?>" />
                </p>
                
                <p style="width: 300px;">
                    <label for='posts_title'>Recent Post Title:</label>
                    <input class="widefat" id="posts_title" name="interlinks_settings[posts_title]" type="text" value="<?php if($interlinks_settings['posts_title']=='') echo "Recent Posts";  else echo $interlinks_settings['posts_title']; ?>" />
                </p>
                                <p style="width: 300px;">
                    <label for='posts_title'>Dont Show Home Link On Posts:</label><br>
                                        <input type="checkbox" name="interlinks_settings[dont_show_home]" <?php if(isset($interlinks_settings['dont_show_home']) && $interlinks_settings['dont_show_home']==true ){ ?>checked="checked"<?php } ?> />  
                            </p>
                                
                <p>
                    <input type='submit' name='btnSaveSettings' id='btnSaveSettings' value="Save Settings" class="button-secondary" />
                </p>
            </form>
        </div>
                    
                    <div style="width:30%; float: left">
                        <div class="ads">
                            <a target="_blank" href="http://www.abbasravji.com/silo1"><img src="http://www.socisynd.com/SiloPlugin/position1.gif"></a>
                        </div>
                        
                         <div class="ads">
                            <a target="_blank" href="http://www.abbasravji.com/silo2"><img src="http://www.socisynd.com/SiloPlugin/position2.jpg"></a>
                        </div>
                        
                         <div class="ads">
                            <a target="_blank" href="http://www.abbasravji.com/silo3"><img src="http://www.socisynd.com/SiloPlugin/position3.gif"></a>
                        </div>
                             
                        
                        
                    </div>
                </div>
                
        <?php
    }
    
    function admin_menu() {
        add_options_page('wpsilos Settings', 'wpsilos Settings', 'manage_options', 'interlinks-settings', array( 'InterLinksManager', 'interlinks_settings_func' ));
    }
}


/** pages **/
//add_action( 'add_meta_boxes', array( 'InterLinksManager', 'interlinks_meta_box' ) );
//add_action( 'admin_enqueue_scripts', array( 'InterLinksManager', 'admin_enqueue' ) );
add_action( 'save_post', array( 'InterLinksManager', 'save_post' ) );
add_filter( 'manage_page_posts_columns', array( 'InterLinksManager', 'interlinks_type_columns' ) );
add_action('manage_page_posts_custom_column', array( 'InterLinksManager', 'interlinks_type_custom_column' ), 10, 2);


/** category management **/
add_action( 'category_add_form_fields' , array( 'InterLinksManager' , 'add_category_fields') , 10 , 10 );
add_action( 'category_edit_form_fields' , array( 'InterLinksManager' , 'edit_category_fields') );
add_action( 'edited_category' , array( 'InterLinksManager' , 'save_category_fields' ) , 10 , 2 );
add_action( 'created_category', array( 'InterLinksManager' , 'save_category_fields' ) , 10 , 2 );


/**custom tables**/
//register_activation_hook( __FILE__, array( 'InterLinksManager', 'install' ) );
add_action( 'admin_menu', array( 'InterLinksManager', 'admin_menu' ) );


/** includes **/
include_once ("widget.php");



Widget Code

Code:
<?phpclass InterLinks_Widget extends WP_Widget {
    function InterLinks_Widget() {  
        $widget_ops = array( 'classname' => 'interlinks_widget', 'description' => 'A widget that displays the Interlinks.' );  
        $control_ops = array( 'width' => 400, 'height' => 450, 'id_base' => 'interlinks_widget-widget' );  
        $this->WP_Widget( 'interlinks_widget-widget', 'InterLinks Widget', $widget_ops, $control_ops );  
    }
    
    function widget( $args, $instance ) {
        extract($instance);
        extract( $args );
        if ( is_home() || is_front_page() ) {
            do_action('home-interlink-page','home');
        } else if ( is_page() ) {
            global $post; 
            $interlink_category = get_post_meta($post->ID, "interlink_category", TRUE);
            if ($interlink_category) {
                do_action('home-interlink-page','page');
                $term = get_term( $interlink_category, 'category' );
                /*
                ?>
                <h3>Category</h3>
                <li><a href="<?php echo get_category_link( $interlink_category );?>"><?php echo $term->name;?></a></li>
                <?php
                */
                do_action('category-recent-posts', $term->term_id);
            }
        } else if ( is_category() ) {
            $cat_id = get_cat_id( single_cat_title( "", FALSE ) );
            $interlink_page = get_option( $cat_id . "_interlink_page" );
             
            $interlink_category = get_post_meta( $interlink_page, "interlink_category", TRUE );
            if ($interlink_category) {
                do_action('home-interlink-page');
                $term = get_term( $interlink_category, 'category' );
                /*
                ?>
                <h3>Category</h3>
                <li><a href="<?php echo get_category_link( $interlink_category );?>"><?php echo $term->name;?></a></li>
                <?php
                */
                do_action('category-recent-posts', $term->term_id);
            }
        } else if ( is_single() ) {
            $category = get_the_category();
            $cat_id = $category[0]->term_id;
            $interlink_page = get_option( $cat_id . "_interlink_page" );
             
            $interlink_category = get_post_meta( $interlink_page, "interlink_category", TRUE );
            if ($interlink_category) {
                            $term = get_term( $interlink_category, 'category' );
                do_action('home-interlink-page',$term->term_id);
                
                /*
                ?>
                <h3>Category</h3>
                <li><a href="<?php echo get_category_link( $interlink_category );?>"><?php echo $term->name;?></a></li>
                <?php
                */
                do_action('category-recent-posts', $term->term_id);
                               
            }
        }
    }
    
    function update( $new_instance, $old_instance ) {
        return $new_instance;
    }
    
    //function form( $instance ) {
        
    //}
    
} 
function register_interlinks_widget() {  
    register_widget( 'InterLinks_Widget' );  
}  
add_action( 'widgets_init', 'register_interlinks_widget' );




function display_home_interlnk_page_link($page=''){
   // echo $page;
       
    $interlinks_settings = get_option("interlinks_settings", TRUE);
    $title_heading = explode("|", $interlinks_settings['title_heading']);?>
      <aside id="recent-posts-5" class="widget widget_recent_entries">        
    <?php
//    if ( !is_home() && !is_front_page() ){
        ?>
        <?php echo $title_heading[0];?><?php echo $interlinks_settings['home_title'];?><?php echo $title_heading[1];?>
        <?php
    //}
    
    // get all pages which are assigned to categories
    $args = array(
        "post_type" => "page",
        "meta_key" => "interlink_category",
        "meta_value" => "1",
        "meta_compare" => ">"
    );
    
    query_posts($args);
        
    ?>
         
    <?php //echo $title_heading[0];?><?php //echo $interlinks_settings['pages_title'];?><?php //echo $title_heading[1];?>
    <ul>
           <?php
            if(( $page!='page' && $page!='home' && !isset($interlinks_settings['dont_show_home']))  || $page=='page' ||  $page=='home' || get_the_ID()==get_option('page_on_front') ){ ?>
            <li><a href='<?php echo home_url();?>'><?php if(isset($interlinks_settings['pages_title']) && $interlinks_settings['pages_title']!='' ) echo $interlinks_settings['pages_title']; else echo 'Home';?></a></li>
    <?php } ?>
                
                <?php
        if ($page=='home' ){
          
    while ( have_posts() ){
        the_post();
                if(get_the_ID()!=get_option('page_on_front')) {
        ?>
        <li><a href="<?php the_permalink();?>"><?php the_title();?></a><br/></li>
        <?php
    }
        }
        }
       else if ($page=='page' ) 
        {
          
           global $post;
            $title = get_the_title($post); 
     //   echo get_option('page_on_front');
             if(get_the_ID()!=get_option('page_on_front') ) {
           ?>
       
           <li><a href="<?php echo get_permalink();?>"><?php  echo $title;?></a><br/></li>
       <?php    
        
        }
        }
        else  {
            global $post; 
            $interlink_category = get_post_meta($post->ID, "interlink_category", TRUE);
                        $term = get_term( $interlink_category, 'category' );
                    //   echo  $interlink_category;
            $args = array(
        "post_type" => "page",
        "meta_key" => "interlink_category",
        "meta_value" => $page,
        "meta_compare" => "="
    );
    
    query_posts($args);
            while ( have_posts() ){
        the_post();
                if(get_the_ID()!=get_option('page_on_front') || isset($interlinks_settings['dont_show_home'])) {
        ?>
        <li><a href="<?php the_permalink();?>"><?php the_title();?></a><br/></li>
        <?php
    }
            }
            
          
        }
        
        
    ?>
    </ul>
          </aside>
    <?php
    wp_reset_query();
}
add_action("home-interlink-page", "display_home_interlnk_page_link");


function display_category_recent_posts($cat_id){
  
    // get all posts of category
    $interlinks_settings = get_option("interlinks_settings", TRUE);
    $title_heading = explode("|", $interlinks_settings['title_heading']);
    $args = array(
        "post_type" => "post",
        'cat' => $cat_id,
        "posts_per_page" => $interlinks_settings["number_of_recent_posts"],
              //  'orderby'=>'rand'
    );
    
        query_posts($args);
    ?>
           <aside id="recent-posts-5" class="widget widget_recent_entries">        
    <?php echo $title_heading[0];?><?php echo $interlinks_settings['posts_title'];?><?php echo $title_heading[1];?>
    <ul>
    <?php
    while ( have_posts() ){
        the_post();
        ?>
        <li><a href="<?php the_permalink();?>"><?php the_title();?></a><br/></li>
        <?php
    }
    ?>
    </ul>
              </aside>
    <?php
    wp_reset_query();
}
add_action("category-recent-posts", "display_category_recent_posts", 10, 2);


function display_interlink_related_posts($content) {
if (is_single()) {
    global $post;
    $current_post = $post->ID;
        $interlinks_settings = get_option("interlinks_settings", TRUE);
        $title_heading = explode("|", $interlinks_settings['title_heading']);
    if(isset($interlinks_settings["number_of_related_posts"]))
        $nopost=$interlinks_settings["number_of_related_posts"];
        else
        $nopost=5;
                
    
$content .='
<style>
    .my-recent-posts ul li {float:left; padding: 2%; width: 20%;height: 70px; list-style-type: none; list-style-position: inside;list-style:none;
    padding-left:0; margin: 0;}
</style>
<div class="my-recent-posts">';
    
  if(isset($interlinks_settings['related_title']) && $interlinks_settings['related_title']!='') { 
 $content .=$title_heading[0].$interlinks_settings['related_title'].$title_heading[1];
    } 
        
     $content .="<ul>";
    
        $i=0;
            $categories = get_the_category();
foreach ($categories as $category) :
    $posts = get_posts('numberposts='.$nopost.'&category='. $category->term_id . '&exclude=' . $current_post.'&orderby=rand');
foreach($posts as $post) :
    $i++;
    
 $content .='<li><a href="'.get_permalink().'">'.get_the_title().'</a></li>';
    if($i==$nopost) break; endforeach; ?><?php  if($i==$nopost) break; 
        
        endforeach;
 $content .='</ul>
</div>';
    
        
        }
               /* if (is_page()) {
    global $post;
    $current_post = $post->ID;
        $interlinks_settings = get_option("interlinks_settings", TRUE);
    $title_heading = explode("|", $interlinks_settings['title_heading']);
    $interlink_category = get_post_meta($post->ID, "interlink_category", TRUE);
    if ($interlink_category) {
    $term = get_term( $interlink_category, 'category' );


    ?>
<style>
    .my-recent-posts ul li {float:left; padding: 2%; width: 20%; height: 70px; list-style-type: none;list-style-position: inside;list-style:none;
    padding-left:0;margin: 0;}
</style>
<div class="my-recent-posts">
    <?php if(isset($interlinks_settings['related_title']) && $interlinks_settings['related_title']!='') { ?>
    <?php echo $title_heading[0];?><?php echo $interlinks_settings['related_title']; ?><?php echo $title_heading[1];?>
    <?php } ?>
    
    <ul>
    <?php
                 if(isset($interlinks_settings["number_of_related_posts"]))
                    $nopost=$interlinks_settings["number_of_related_posts"];
                    else
                 $nopost=5;
                    
                    $nopost=2;
                    
    $posts = get_posts('numberposts='.$nopost.'&category='.  $term->term_id . '&exclude=' . $current_post);
foreach($posts as $post) :
    ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endforeach; ?>
</ul>
</div>
    <?php
        } }*/
             
    wp_reset_query();
           return $content;
        
}
add_action('the_content', 'display_interlink_related_posts');



Thanks for your help :)

Edit: Aw, wrong section I guess. :/ Sorry
 
Last edited:
Back
Top