How to check if there is image title, caption, description?
It’s more a programming question, but try this: $post = get_post( get_post_thumbnail_id() ); if ( !isset( $post->post_title ) ) { echo ‘Sorry no title’; } else { echo $post->post_title; }
It’s more a programming question, but try this: $post = get_post( get_post_thumbnail_id() ); if ( !isset( $post->post_title ) ) { echo ‘Sorry no title’; } else { echo $post->post_title; }
This would be an appropriate use of query_posts(), with a post custom meta query. Since you’re querying by meta_key=featured_article&meta_value=on, you would then exclude on the same parameters. <?php // Setup the custom meta-query args $exclude_featured_args = array( ‘meta_query’ => array( array( ‘key’ => ‘featured_article’, ‘value’ => ‘on’, ‘compare’ => ‘!=’ ) ) ); // globalize … Read more
Add this to functions.php: // Pagination function pagination($pages=””, $range = 4) { $showitems = ($range * 2)+1; global $paged; if(empty($paged)) $paged = 1; if($pages == ”) { global $wp_query; $pages = $wp_query->max_num_pages; if(!$pages) { $pages = 1; } } if(1 != $pages) { echo “<div class=\”pagination\”><span>Page “.$paged.” of “.$pages.”</span>”; if($paged > 2 && $paged > … Read more
In short no – the template used is based on the query, and when paginating you are essentially repeating the same query, but for a different page. In general the template will be the same. archive.php can be used for most queries, but often preferable templates exist (e.g. category templates, tag templates, author templates etc.). … Read more
OK, after reading Rarst post i went with the taxonomy term option. It was very simple: Just after the register_taxonomy call, i added one line of code wp_insert_term(‘Featured’,’filter’); being filter my taxonomy. Then I modified the query in the template, adding the line ‘filter’ => ‘Featured’, inside the args. Now I only see the featured … Read more
<?php /* Set the name of the category and the number os posts to be displayed */?> <?php $first_query = new WP_Query(‘category_name=name&posts_per_page=7’); ?> <?php /* Show the posts */ ?> <?php while ($first_query->have_posts()) : $first_query->the_post(); ?> <?php /* Make the hiperlink to the post */ ?> <a href=”https://wordpress.stackexchange.com/questions/59934/<?php the_permalink(); ?>”> <?php /* Get the featured … Read more
There are a few errors which I want to address First of all, you should never use query_posts to construct custom queries. This is not just my emphasis, but the codex as well. The one big problem with query_posts is, it many circumstances, pagination fails Note: This function isn’t meant to be used by plugins … Read more
WordPress by default provides such feature named “Sticky Posts”. you can mark any post as sticky from “Quick Edit” link. and WordPress will add a post class named sticky with all sticky posts. so you can use this class in your CSS for giving custom styles. and another solutions is to create custom post meta … Read more
The answer is eager loading or cache or both. Eager loading Have a look to this pseudo-code: $ids = get_ids_from_a_db_table(); foreach ( $ids as $id ) { $row = get_row_from_foreign_table_using( $id ); echo “Row title for the ID: $id is $row->title”; } If the number of $ids is n than this simple code runs n+1 … Read more
A simple and effective approach const editor = wp.data.select(‘core/editor’); const imageId = editor.getEditedPostAttribute(‘featured_media’); const imageObj = wp.data.select(‘core’).getMedia(imageId); ImageObj gives you a reasonable amount of image data to work with.