Website Tutorial WordPress display related articles
WordPress display related articles <?php $tags = wp_get_post_tags($post->ID); if ($tags) { $first_tag = $tags[0]->term_id; $args=array( ‘tag__in’ => array($first_tag), ‘post__not_in’ => array($post->ID), ‘showposts’=>10, ‘caller_get_posts’=>1 ); $my_query = new WP_Query($args); if( $my_query->have_posts() ) { while ($my_query->have_posts()) : $my_query->the_post(); ?> <li><a href=”<?php the_permalink() ?>” rel=”bookmark” title=”<?php the_title_attribute(); ?>”><?php the_title();?> <?php comments_number(‘ ‘,’(1)’,’(%)’); ?></a></li> <?php endwhile; } } wp_reset_query();…
Website Tutorial WordPress display the latest comment
WordPress display the latest comment <?php global $wpdb; $sql = “SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type,comment_author_url, SUBSTRING(comment_content,1,30) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) WHERE comment_approved = ’1′ AND comment_type = ” AND post_password = ” ORDER BY comment_date_gmt DESC LIMIT 10″; $comments = $wpdb->get_results($sql);…
Website Tutorial wordpress display random articles
<?php $rand_posts = get_posts(‘numberposts=10&orderby=rand’); foreach( $rand_posts as $post ) : ?> <li><a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a></li> <?php endforeach; ?>
Website Tutorial WordPress-Change the blog name and description
In header.php, the following two lines of code are used to display the blog name and description: ~~~ <h1 id=”logo” class=”grid_4″>BBBBF</h1> <h2 class=”grid_12 caption clearfix”>Our <span>blog</span>, keeping you up-to-date on our latest news.</h2> ~~~ The above is static code, now make the following changes: ~~~ <h1 id=”logo” class=”grid_4″><a href=”<?php%20echo%20get_option(‘home’);%20?>/”><?php bloginfo(‘name’); ?></a></h1> <h2 class=”grid_12 caption clearfix”><?php…
Website Tutorial WordPress theme-Change the stylesheet style.css path
WordPress theme-Change the stylesheet style.css path Before this, the homepage you saw was messy because the css style had not been loaded. Now let’s add the style together. You can find this code in header.php: `<link rel=”stylesheet” href=”./style.css” type=”text/css” media=”screen” /> ` You may ask: Isn’t there already a style.css in the wp-content\themes\bbbbf directory? Then…
Website Tutorial WordPress theme-create header.php
WordPress theme-create header.php Next, create a new PHP file header.php in the theme directory wp-content\themes\bbbbf we created last time. We extract the header code in index.php and copy and paste it into header.php. The following code is all the code in header.php (of course, the header code of different themes is different, and you can…
Website Tutorial WordPress template main file composition
Theme file composition Before you start making a WordPress theme, you must first understand what files the WordPress theme is made of, and you must know how the WordPress program is connected to the theme file. The following are all the template files in the default folder of the WordPress default theme. After looking at…
Website Tutorial How to Only Get the WordPress Featured Image URL
To get the URL of the featured image (also known as the post thumbnail) in WordPress, you can use the get_the_post_thumbnail_url() function. This function retrieves the URL of the featured image for a given post. Here’s how you can use it: For a Specific Post ID If you want to get the featured image URL…
Website Tutorial WordPress get the last modified time of the article with the specified id
To get the last modified time of an article in WordPress given its ID, you can use the get_post_modified_time function. Here’s how you can do it: <?php $post_id = 5;$last_modified_time = get_post_modified_time(‘Y-m-d H:i:s’, true, $post_id); echo ‘last_modified_time: ‘ . $last_modified_time; ?> Explanation: get_post_modified_time(): This function retrieves the last modification time of a post. The first…