Excluding posts from menu wordpress - wordpress

I am trying to exclude multiple posts from the menu by the wp_nav_menu exclude parameter but that does not work the way I want it. Only page with id 58 is excluded If I run the following lines of code:
<?php wp_nav_menu( array(
'exclude' => '58, 59, 60',
'fallback_cb' => 'bfa_page_menu'
) ); ?>
If I pass the IDs as an array the menu just crashes.
Any help is much appreciated.

This is covered here http://9-sec.com/2012/10/how-to-exclude-pages-from-wp_nav_menu-2/
The other option is to use a custom walker function.

Related

Child page for every category Wordpress

I create in my wordpress theme template page named popular.php, where i sort post by popularity. It works fine for every post but I dont know how to do this for category.
I want something like this:
sitename.com/popular-post - works fine
sitename.com/category-name/popular-post - i don't know how to make popular page child for every category?
Popular loop works fine with this args:
<?php $current_category_ID = getCurrentCatID(); ?>
<?php $args = array(
'posts_per_page' => 60,
'cat' => $current_category_ID,
'meta_key' => 'views',
'orderby' => 'meta_value_num',
'order' => 'DESC',
); ?>
<?php query_posts($args); ?>
Only I don't know make it child for category?
Check Permalink Settings & update the custom structure like this
/%category%/%postname%/
https://codex.wordpress.org/Category_Templates
See this page in the codex. It explains how to name your template files for category.
For example, if you have a file in your theme named category.php, that template will be used to display a category page.

Wordpress query from Magento/WHMCS return wrong result

I am trying to display posts from a specific cateogry in WordPress in a footer column on a site. It works fine unless the footer is displaying on a page that is integrated in either WHMCS or Magento. For some reason, on those pages within those apps, it still displays the blog post column, but instead of returning the last X # of posts in the specified category, it seems to return the last post X # of times.
For example, here is the stand alone Wordpress blog column pulling from a specific category:
http://www.thinkshovels.com/includes/latest_work.php
This is exactly what we want shown throughout the site, however if you visit http://www.thinkshovels.com/service/ you can see that the middle column is not displaying that info.
Here is the code querying wordpress:
define('WP_USE_THEMES', false);
require('/home/shovels/public_html/blog/wp-load.php');
$qarray = array('cat' => '5', 'posts_per_page' => 4);
query_posts($qarray);
while (have_posts()): the_post();
$args = array( 'post_type' => 'attachment', 'numberposts' => -1,
'post_status' => null, 'post_parent' => $post->ID );
I'm not sure if I have done something wrong here, or if there is a better way to approach this, but it seems that WHMCS and Magento break something with these queries.
Any tips/advice appreciated! Thanks.
Instead of query_posts try to use get_posts instead.
According to the article from Developer.WordPress.com you should avoid using query_posts.

List child pages of the current page's parent

I'm developing a WordPress theme using version 3.5.1, and in every page I want to display a side vertical menu displaying all the pages that belong to the current's page parent.
I've tried with this:
<?php
$args = array(
'sort_column' => 'menu_order',
'child_of' => $post->parent
);
?>
<ul>
<?php wp_list_pages($args); ?>
</ul>
But what I get listed is every parent page, instead of what I pretend to do.
What is the best approach to do this?
Thank you very much in advance!
That's a syntax error.
Try this: 'child_of' => $post->post_parent
That should return the siblings of the page you're in.

How to print a custom menu in Drupal 7?

I have created a menu in Drupal 7 and created links to pages under that menu.
I named my new menu "Site Menu"
In my page.tpl.php where I want my menu to appear I have put this in place:
<?php print theme('links', menu_navigation_links('menu-site-menu')); ?>
After I have cleared my cache and refreshed my page my menu doesn't appear.
I am stumped. Any help would be greatly appreciated.
Berdir answer is correct. Drupal 7 theme_links function also more vastly uses arrays. For example if you would like to add another class name to the so that it is you would code it like this:
<?php print theme('links', array('links' => menu_navigation_links('menu-site-menu'), 'attributes' => array('class'=> array('links', 'site-menu')) ));?>
theme() now recieves an array of arguments. For example:
<?php
print theme('links', array('links' => menu_navigation_links('menu-site-menu')));
?>
Well, it is bit confusing from above solutions to print menu. But below code worked for me, hope this will work for y'all,
$search_menu_name = "menu-search-box-menu";
print theme('links', array('links' => menu_navigation_links($search_menu_name), 'attributes' => array('id' => $search_menu_name, 'class'=> array('links', 'inline'))));
The above code is like this, "menu-search-box-menu" is my custom menu name/ID. You can find it in that particular menu edit link.
Enjoy. :)

How do I display just the children of the parent term on a taxonomy archive page?

Basically, I have created a custom post type and a custom taxonomy for that custom post. The custom taxonomy is hierarchical and the client plans on adding hundreds of categories. Because of this, they want the main page to display only the top level parent which is easy enough. However they want a drill down menu which only shows the parent and the children of the parent so they don't overwhelm the user. I think that what I basically need to do is get the parent id of the child so I can call up just those children.
I have been digging around and the code below is what I have come up with which I know if still far off from what it needs to be. Can you shed any light on this or at least give me a push in the right direction? I'm totally lossed.
I included the code below but I also put in pastebin at http://pastebin.com/B8qtz6Lf
<?php if (is_tax()) {
$this_term = get_term();
if (get_term_children($this_term->term_ID) != "") {
echo "<h2>Subcategories</h2>";
wp_list_categories( array (
'title_li' => '',
'depth' => '1',
'child_of' => '.$this_term->term_ID'
));
}
} else {
wp_list_categories( array(
'taxonomy' => 'compliance_categories',
'title_li' => '',
'depth' => '1'
));
}
?>
Any help you can give me would be awesome!
Not sure if this may help, but here is how I've been able to query a custom taxonomy within a custom post type. This may help you achieve what you're looking for.
$loop = new WP_Query(array('post_type' => 'products', 'product-type' => 'projectors'));
while ($loop->have_posts()) : $loop->the_post();
In this query, the custom post type is "products", the taxonomy is "product-type" and the category within that taxonomy is "projectors". This query will only show anything in the "projectors" category.
Hope that can give you some ideas to try.

Resources