Solved

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

Posted on 2010-11-23
6
484 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

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…
So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

770 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