• Resolved ianworksword

    (@ianworksword)


    I apologize for posting this already under ‘extend’, i made a mistake. Like many others, i merely want my home page to list along with the other pages that are called via wp_list_page. However, I would be very happy with a simple workaround.

    I want to be able to widgets (in this case the pages widget) as I am setting up this site for others to use and change. After reading several articles on this, I am wondering if it is possible to insert code into the widget.php file that makes the index.php file also list along with the pages? While I am just learning how to code php, i do understand the basics, and am comfortable customizing html & css pages. Is what I am asking possible to do? I couldn’t seem to find another support post about actually adding code to the widget to make the home page show up as a link. I don’t even want to be able to edit its order; it can just sit on top of the list that is generated by wp_list-page.

    Maybe one would start to do this at line 329 in widgets.php? Thank you for any help or suggestions you have.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Well, an easy way to add a link to the home page would be:

    <ul>
    <li><a href="https://homepagelink.com">Home</a></li>
    <?php
    wp_list_pages('title_li=');
    ?>
    </ul>
    Thread Starter ianworksword

    (@ianworksword)

    Thanks dave. But you’re not suggesting adding this into the widget.php file somehow right? As it stands, I want the home page to be in the same list as the pages (which your code would do). Normally I could just hard code this into the sidebar. But with widgets enabled, the widgets will replace all of the code that would be in the sidebar.php file. How do I get this to work with the pages widget do you think? (I imagine that there is a simple way to put this in the widget. I did some experimenting, but um… well ‘parsed the code’ i think is the right term, and it didn’t work.) Again, I know enough to try things and not mess anything up, but not enough to solve this without days of experimenting and learning (which someone else can probably solve in a second). Thank you very much for your help thus far.

    Try doing this:

    Find the code below in the widgets.php file, it should be towards the end, mine was directly underneath the commented line that said “Standard Widgets”.

    function widget_pages($args) {
    	extract($args);
    	$options = get_option('widget_pages');
    	$title = empty($options['title']) ? __('Pages') : $options['title'];
    	echo $before_widget . $before_title . $title . $after_title . "<ul>\n";
    	wp_list_pages("title_li=");
    	echo "</ul>\n" . $after_widget;
    }

    Now try adding this line:

    function widget_pages($args) {
    	extract($args);
    	$options = get_option('widget_pages');
    	$title = empty($options['title']) ? __('Pages') : $options['title'];
    	echo $before_widget . $before_title . $title . $after_title . "<ul>\n";

    echo '<li><a href="https://homepagelink.com">Home</a></li>';

    wp_list_pages("title_li=");
    	echo "</ul>\n" . $after_widget;
    }

    I don’t have any way to test this right now, so it may not work. Let me know!

    Thread Starter ianworksword

    (@ianworksword)

    Dave: This does indeed place a home link. My functions are a little different probably because of the theme I am using. Here is what my code says, starting from the same place you were talking about. I marked where I put in the new code as /** New Line **/:

    function wp_widget_pages( $args ) {
    	extract( $args );
    	$options = get_option( 'widget_pages' );
    
    	$title = empty( $options['title'] ) ? __( 'Pages' ) : $options['title'];
    	$sortby = empty( $options['sortby'] ) ? 'menu_order' : $options['sortby'];
    	$exclude = empty( $options['exclude'] ) ? '' : '&exclude=' . $options['exclude'];
    
    	if ( $sortby == 'menu_order' ) {
    		$sortby = 'menu_order, post_title';
    	}
    /** NEW LINE **/ echo '<li><a href="https://www.yahoo.com">Home</a></li>';
    
    	$out = wp_list_pages('title_li=&echo=0&sort_column=' . $sortby . $exclude );
    
    	if ( !empty( $out ) ) {
    ?>
    	<?php echo $before_widget; ?>
    		<?php echo $before_title . $title . $after_title; ?>
    		<ul>
    			<?php echo $out; ?>
    		</ul>
    	<?php echo $after_widget; ?>
    <?php
    	}
    }

    HOWEVER, this places it not actually in the list….. well it places it in the widget, but not at the top of the unordered list. I tried placing the code right in with the the variable that calls wp_list_pages (i.e. this line:

    $out = wp_list_pages('title_li=&echo=0&sort_column=' . $sortby . $exclude );

    But i couldn’t get it to work. Looking at the code above, is there another recommendation that you have for how to make the home link part of the list? You can see an example of how it isn’t quite working here: https://sandiandneil.com.s20901.gridserver.com/

    Double thank you’s for all of your help thus far. I can tell that I am almost there. (The function widget_pages_control) is the next function, for whatever that is worth).

    – ian

    Thread Starter ianworksword

    (@ianworksword)

    For what it is worth i figured it out. Here is where i inserted the code into the widget.php file:

    <?php echo $before_widget; ?>
    		<?php echo $before_title . $title . $after_title; ?>
    		<ul>
    			<?php /* NEW CODE HERE*/ echo '<li><a href="https://www.yahoo.com">Home</a></li>'; /* END NEW CODE*/ echo $out; ?>
    		</ul>
    	<?php echo $after_widget; ?>

    This at the end of the wp_pages_widget function, and just before the wp_widget_pages_control section of that function. (If that is the right thing to call it.) So there is the solution (at least in my case). Thank you so much for your help. It would not have been possible otherwise.

    This has been posted just a few hours ago:
    https://www.ads-software.com/support/topic/128406?replies=1
    (homepage link plugin)

    Thread Starter ianworksword

    (@ianworksword)

    I am glad there is now a plugin for this. Much easier than smacking my head against the desk. Thanks moshu for making the connection.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Adding HOME page to PAGE LIST’ is closed to new replies.