Tag Info

New answers tagged

0

You shouldn't use query_posts functions. You should create instance of WP_Query class In your theme folder create a new file called category-slug.php. You can copy the category.php file or archive.php file to create category-slug.php file. Then in the new category-slug.php file before the while loop you can write your query. $query = new WP_Query( ...


1

You could use get_attached_media() function to check if the post has any attached images to it. Also, you use wrong logic operator. Your code would look like this: $attached_images = get_attached_media('image', $post->ID); if ( (get_the_post_thumbnail() == NULL) && empty($attached_images) ) { // show your default image } else { // do nothing, I ...


0

For this situation, I create a custom page template, say tpl-archive-page.php. For example using Advanced Custom Fields and the Post Type Selector Field(*) the user can choose a post type to connect to. <?php /** * Template Name: CPT Archive Page */ get_header(); while (have_posts()) : the_post(); get_template_part('content', 'page'); ...


0

I would... Create a CPT registered with 'has_archive' => false and use that as your "editable content" source. Or use a simple "Page" if you prefer Then create archive-{cpt-name}.php in the theme and query in that template for the content CPT data, or for the "Page" data.


1

To display monthly archives arranged by year, you can use this code. It checks through each month if WordPress have any post in that month and create archive. <?php global $wpdb; $limit = 0; $year_prev = null; $months = $wpdb->get_results( "SELECT DISTINCT MONTH( post_date ) AS month , YEAR( post_date ) AS year, COUNT( id ) as ...


0

thank u all i just did a simple code to get what i want <?php $prevyear = date('2150') - 0001; $nextyear = date('2150') + 0001; $prevmonth = date('01') - 01; $nextmonth = date('01') + 01; echo echo get_year_link($prevyear)."<br />".get_year_link($nextyear)."<br />".get_year_link($prevmonth)."<br />".get_year_link($nextmonth)."<br ...


0

I added this to my child-theme's functions.php file and it works 100% add_action( 'template_redirect', 'redirect_archive' ); function redirect_archive() { if ( is_tax('location') ) { $termurl = get_query_var( 'term' ); wp_redirect( home_url('/search/location/'.$termurl), 301 ); exit; } }



Top 50 recent answers are included