Show children of top level category only

Imagine i have a URL structure like this: www.domain.com/category/subcategory/ This is my code: <?php $args=array( ‘child_of’ => $cat-id, ‘hide_empty’ => 0, ‘orderby’ => ‘name’, ‘order’ => ‘ASC’ ); $categories=get_categories($args); foreach($categories as $category) { echo ‘<a href=”‘ . get_category_link( $category->term_id ) . ‘” title=”‘ . sprintf( __( “View all posts in %s” ), $category->name ) . … Read more

Exclude the parent custom post-type posts only

Not sure if this is possible without some form of hard-coding but I have a custom post-type called ‘city’. Within the ‘city’ post-type I have some parent post (e.g. England, America and China) and some child posts (London, Washington DC and Beijing). I have a query that displays all of the posts under ‘city’. But … Read more

Multiple Conditions for Child Page Title

I’ve been trying to work with Conditional Tags and cannot wrap my head around this problem. PHP novice here. On sub-pages I need to display the parent page title as well as the page title. I have it working with this: <h1><?php echo get_the_title($post->post_parent);?></h1> <h2><?php the_title(); ?></h2> But the problem I have now is that … Read more

jquery if div id has children

This if-condition is what’s giving me trouble: if (div id=myfav has children) { do something } else { do something else } I tried all the following: if ( $(‘#myfav:hasChildren’) ) { do something } if ( $(‘#myfav’).children() ) { do something } if ( $(‘#myfav:empty’) ) { do something } if ( $(‘#myfav:not(:has(*))’) ) … Read more

Best way to get child nodes

I was wondering, JavaScript offers a variety of methods to get the first child element from any element, but which is the best? By best, I mean: most cross-browser compatible, fastest, most comprehensive and predictable when it comes to behaviour. A list of methods/properties I use as aliases: var elem = document.getElementById(‘container’); var child = … Read more