Listing pages which uses specific template [duplicate]

You can do this with a WP_Query meta_query. The page template filename is stored in post meta under the key _wp_page_template: $args = array( ‘post_type’ => ‘page’, ‘posts_per_page’ => -1, ‘meta_query’ => array( array( ‘key’ => ‘_wp_page_template’, ‘value’ => ‘product.php’ ) ) ); $the_pages = new WP_Query( $args ); if( $the_pages->have_posts() ){ while( $the_pages->have_posts() ){ … Read more

wp_nav_menu: show menu only if one exists, otherwise show nothing

Use has_nav_menu(), and test for theme_location, rather than menu_id: <?php if ( has_nav_menu( $theme_location ) ) { // User has assigned menu to this location; // output it wp_nav_menu( array( ‘theme_location’ => $theme_location, ‘menu_class’ => ‘nav’, ‘container’ => ” ) ); } ?> You can output alternate content, by adding an else clause. EDIT You … Read more

How to show a hierarchical terms list?

Use wp_list_categories with the ‘taxonomy’ => ‘taxonomy’ argument, it’s built for creating hierarchical category lists but will also support using a custom taxonomy.. Codex Example: Display terms in a custom taxonomy If the list comes back looking flat, it’s possible you just need a little CSS to add padding to the lists, so you can … Read more

Does Python have an immutable list?

Yes. It’s called a tuple. So, instead of [1,2] which is a list and which can be mutated, (1,2) is a tuple and cannot. Further Information: A one-element tuple cannot be instantiated by writing (1), instead, you need to write (1,). This is because the interpreter has various other uses for parentheses. You can also do away with parentheses altogether: 1,2 is the same as (1,2) Note that a tuple is … Read more

Quickest way to compare two generic lists for differences

Use Except: I suspect there are approaches which would actually be marginally faster than this, but even this will be vastly faster than your O(N * M) approach. If you want to combine these, you could create a method with the above and then a return statement: One point to note is that there is … Read more

Python initializing a list of lists

The problem is that they’re all the same exact list in memory. When you use the [x]*n syntax, what you get is a list of n many x objects, but they’re all references to the same object. They’re not distinct instances, rather, just n references to the same instance. To make a list of 3 different lists, do this: This gives you 3 … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)