Solved

wordpress - how to get rid of parent menu item in sidebar

Posted on 2010-11-23
6
486 Views
Last Modified: 2012-08-13
Notice on this page how the "In The News" section is highlighted.

http://pacificcenterplasticsurgery.com/newsite/news/

There is also an "In the News" header at the top of the sidebar:
<h2 class="sidebartitle">In the News</h2>

I don't want this h2 to show when I go to the "In the News" page. I just want the "In the News" link to show. The one that is currently below the "Plasticos Foundation" link in the sidebar.

Thanks!
0
Comment
Question by:phillystyle123
  • 4
  • 2
6 Comments
 
LVL 17

Expert Comment

by:jrm213jrm213
ID: 34200330
edit sidebar.php to not display that h2 if on that page...

can you post the contents or upload your sidebar.php?
0
 

Author Comment

by:phillystyle123
ID: 34200549
Thanks for the reply,

sidebar attached. Actually, what I'd really like to do is to list a page that is using "In the News" as a parent underneath the "In the News" link so if you were on this page:

http://pacificcenterplasticsurgery.com/newsite/blog/

<h2 class="sidebartitle">In the News</h2> wouldn't appear and the sidebar would output as follows:

Plasticos Foundation
In the News
>Articles (In the News is the parent)
Read Our Blog

Perhaps I need to make the "In the News link go away instead?
<ul>
  <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>
    <?php
    global $notfound;
    if (is_page() and ($notfound != '1')) {
        $current_page = $post->ID;
        while($current_page) {
            $page_query = $wpdb->get_row("SELECT ID, post_title, post_status, post_parent FROM $wpdb->posts WHERE ID = '$current_page'");
            $current_page = $page_query->post_parent;
        }
        $parent_id = $page_query->ID;
        $parent_title = $page_query->post_title;
	?>
	
	
	<?php
        // if ($wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = '$parent_id' AND post_status != 'attachment'")) {
        if ($wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = '$parent_id' AND post_type != 'attachment'")) {
    ?>

    <?php } } ?>
	
	
		<?php wp_list_categories('sort_column=name&optioncount=1&hierarchical=0&title_li=<h2 class="sidebartitle">' . __('Categories') . '</h2>'); ?>
    <li class="widget">
      <h2 class="sidebartitle"><?php _e('Archives'); ?></h2>
	  
      <ul class="list-archives">
        <?php wp_get_archives('type=monthly'); ?>
      </ul>
	 
    </li>
    <li class="widget">
      <h2 class="sidebartitle"><?php _e('Links'); ?></h2>
      <ul class="list-blogroll">
        <?php 
			$links = get_bookmarks('orderby=name&order=ASC&limit=-1'); 
			foreach($links as $link){
				echo '<li><a href="'.$link -> link_url.'">'.$link -> link_name.'</a></li>';
			}
		?>
      </ul>
    </li>
	<li class="widget">
      <h2 class="sidebartitle">Meta</h2>
      <ul class="list-meta">
		<li><a href="<?php bloginfo('rss2_url'); ?>" title="<?php _e('Syndicate this site using RSS'); ?>"><?php _e('<abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
		<li><a href="<?php bloginfo('comments_rss2_url'); ?>" title="<?php _e('The latest comments to all posts in RSS'); ?>"><?php _e('Comments <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
		<li><a href="http://mythem.es/" title="mythem.es">My Themes</a></li>
		<?php wp_meta(); ?>
      </ul>
    </li>
  <?php endif; ?>
 </ul>
<!--/sidebar -->

Open in new window

0
 
LVL 17

Expert Comment

by:jrm213jrm213
ID: 34200630
ok so to get rid of the <h2> at the top of the sidebar

remove

&title_li=<h2 class="sidebartitle">' . __('Categories') . '</h2>'

from the call to wp_list_categories at linie 24 above



In order to do what you are specifying as far as listing pages under a specific category, you can do that but there isn't a function to just do it, you will have to get your data and then run some replaces to inject the pages into the correct spot.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:phillystyle123
ID: 34200690
i only want to get rid of it for the "In the News" page - is there some sort of conditional I can use ala
<?php if ( is_front_page() ) { ?>?
0
 
LVL 17

Expert Comment

by:jrm213jrm213
ID: 34200720
unfortunately, not that I know of. You will most likely need to build the menu yourself using get_categories
0
 
LVL 17

Accepted Solution

by:
jrm213jrm213 earned 500 total points
ID: 34200802
oh you know what you could do though...

you could use

if is_category to surround the whole statement and use two different wp_list_categories calls. I initially thought you meant a conditional for inside the wp_list_categories parameter string...

if is_category(['id,title or slug  of your category'])
{
   wp_list_categories('sort_column=name&optioncount=1&hierarchical=0');
}else
{
wp_list_categories('sort_column=name&optioncount=1&hierarchical=0&title_li=<h2 class="sidebartitle">' . __('Categories') . '</h2>');
}
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question