Static Front-Page Excerpts

Is there any particular reason not to use the front-page.php template file, and just not bother with trying to pull WordPress headers into external files? Using the front-page.php template file is easy: Create a new static Page, with any arbitrary name (let’s call it “Front Page”) Go to Dashboard -> Settings -> Reading and set … Read more

Custom URL for all posts in WordPress

Create a page with a custom page template, then create a custom WP_Query object to return your last posts. You can get something like: <?php /* Template Name: Blog Page */ get_header(); $args = array( ‘post_type’ => ‘any’, #all post types ‘posts_per_page’ => 10 #get 10 posts ); $query = new WP_Query( $args ); if($query->have_posts()): … Read more

How to show only posts with images?

No need for post IDs what has no thumbnail. Use meta query to get only those what has thumbnail. Add meta query function get_only_posts_with_images( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( ‘meta_query’, array( array( ‘key’ => ‘_thumbnail_id’ ) ) ); } } add_action( ‘pre_get_posts’, ‘get_only_posts_with_images’ ); Or use custom query. $query … Read more

if I create ‘front-page.php’, then how do I link to post index?

Since WordPress 4.5 you can use get_post_type_archive_link( ‘post’ ) to link to the page containing the blog posts. Depending on what you’ve set under Settings -> Reading, this will be either the front page, e.g. example.com/ or a specific page like example.com/news/. home_url( “https://wordpress.stackexchange.com/” ) always points to the front page.

How to target only the front page (not subsequent paginated pages) in theme/plugin?

You have a misconception about is_front_page(). Lets look at the source: public function is_front_page() { // most likely case if ( ‘posts’ == get_option( ‘show_on_front’) && $this->is_home() ) return true; elseif ( ‘page’ == get_option( ‘show_on_front’) && get_option( ‘page_on_front’ ) && $this->is_page( get_option( ‘page_on_front’ ) ) ) return true; else return false; } So from … Read more

Loop on front-page.php

This is how you would do it. You’re loop is based on being in an archive or index page. (or home) $args = array( ‘posts_per_page’ => 3, ‘post_type’ => ‘post’, //choose post type here ‘order’ => ‘DESC’, ); // query $the_query = new WP_Query( $args ); if( $the_query->have_posts() ): while( $the_query->have_posts() ) : $the_query->the_post(); get_template_part(‘loop’); … Read more

Performing a POST action on homepage goes to posts page

When posting a form, if you use ‘name’ as an input name then there seems to be a problem with submitting. Try changing: <input type=”text” name=”name” class=”form-contact__text” /> to: <input type=”text” name=”the_name” class=”form-contact__text” /> Also, best to give your submit button a more unique name in case it conflicts with any plugins/themes – then check … Read more

Pagination not Working on only Front page on latest verson of WordPress

this is proper working code for pagination on forntpage if ( get_query_var(‘paged’) ) { $paged = get_query_var(‘paged’); } elseif ( get_query_var(‘page’) ) { $paged = get_query_var(‘page’); } else { $paged = 1; } $args = array( ‘post_type’ => ‘post’, ‘posts_per_page’ => 8, ‘post_status’ => ‘publish’, ‘paged’ => $paged ); $loop = new WP_Query( $args ); … Read more

How to display thumbnail and excerpt of a page on homepage?

<?php $post_id = 50; // assign post id $queried_post = get_page($post_id); if(is_home()) { ?> <div class=”product_title”><h3><a href=”https://wordpress.stackexchange.com/questions/72514/<?php echo get_page_link($post_id); ?>”><?php echo $queried_post->post_title; ?></a></h3></div> <div class=”product_image_location”><?php echo get_the_post_thumbnail( $post_id); ?></div> <div class=”description_product”> <?php echo $queried_post->post_content; ?></div> <?php } ?>

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