I have Created custom template in WordPress its working for English with WPML plugin, but when I change language to Dutch language in custom template so it's not change Dutch language for custom template.
Please check the screenshot:
https://prnt.sc/tibvMuUL3jIh (English Language)
https://prnt.sc/EqzfIWRL5Jop (Dutch Language)
<?php $args = array(
'post_type' => 'stories',
'posts_per_page' => '3',
);
$query = new WP_Query($args); ?>
<?php if ($query->have_posts() ) : ?>
<?php
while ($query->have_posts() ) :
$query->the_post();
$test = get_post_meta(get_the_ID());
$img_atts = wp_get_attachment_image_url($test['profile_image'][0]);
?>
<div class="content_story">
<div class="story-col">
<div class="story_main">
<?php if(!empty($img_atts)) { ?>
<img src="<?php echo $img_atts; ?>">
<?php } else { ?>
<img src="https://ourforeverstories.com/wp-content/uploads/2022/04/search.png">
<?php }?>
<h3><?php echo $test['firstname'][0].' '.$test['lastname'][0]; ?></h3>
<p><?php echo $test['date_of_birth'][0]?></p>
<p><?php echo $test['Place_of_birth'][0]?></p>
</div>
</div>
</div>
<?php endwhile; ?>
Related
I have the code to display the latest posts on my website, but I wonder if there is a way to make a list of the latest posts, displaying only one post per category. Let's say I have 7 categories, so only 7 posts will be displayed on the page. What should I do?
<?php if ( ! is_single() ) { ?>
<div class="post-container">
<?php } ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php
//Post Title code
//Post Thumbnail code
//Post Content / Excerpt code
//Post Meta code
</article> <!-- /post -->
<?php if ( ! is_single() ) { ?>
</div>
<?php
<?php } ?>
It's very easy to add latest post from each category.
First of all get all the categories of blog by using below code:
$categories = get_categories();
Then use foreach ( $categories as $category ) {} to tell WordPress to run through each of these categories in turn and run the code inside the braces.
Now you need to define the arguments for your query. Inside the braces, add this:
$args = array(
'cat' => $category->term_id,
'post_type' => 'post',
'posts_per_page' => '1',
);
Next, insert your query, using the WP_Query class:
$query = new WP_Query( $args );
if ( $query->have_posts() ) { ?>
<section class="<?php echo $category->name; ?> listing">
<h2>Latest in <?php echo $category->name; ?>:</h2>
<?php while ( $query->have_posts() ) {
$query->the_post();
?>
<article id="post-<?php the_ID(); ?>" <?php post_class( 'category-listing' ); ?>>
<?php if ( has_post_thumbnail() ) { ?>
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail( 'thumbnail' ); ?>
</a>
<?php } ?>
<h3 class="entry-title">
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</h3>
<?php the_excerpt( __( 'Continue Reading <span class="meta-nav">→</span>', 'twentyfourteen' ) ); ?>
</article>
<?php } // end while ?>
</section>
<?php } // end if
// Use reset to restore original query.
wp_reset_postdata();
This will display each category posts in your home page. Please try to use it and let me know if you have any issue.
This could be a dumb question, but I just can't figure it out. I'm working on a custom WordPress theme I created by converting a html website. But when I use WP_Query, it doesn't load my blog posts. Yes, it displays a list of blog posts as it should with the loop, but when I click on each title or the 'read more' link of a post, it only changes the url in the address bar to the link of the post and then simply refreshes the hope page. It doesn't open I'm really tired. Here's the query loop in my index.php
<?php
$categories = get_categories();
foreach ( $categories as $category ) {
//define args for query
$args = array(
'cat' => $category->term_id,
'post_type' => 'post',
'posts_per_page' => '30',
);
//The main query
$query = new WP_Query( $args );
if ( $query->have_posts() ) { ?>
<section class="<?php echo $category->name; ?> listing">
<h2>Latest in <?php echo $category->name; ?>:</h2>
<?php while ( $query->have_posts() ) {
$query->the_post();
?>
<article id="post-<?php the_ID(); ?>" <?php post_class( 'category-listing' ); ?>>
<?php if ( has_post_thumbnail() ) { ?>
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail( 'thumbnail' ); ?>
</a>
<?php } ?>
<h3 class="entry-title">
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</h3>
<?php the_excerpt(); ?>
</article>
<?php } // end while ?>
</section>
<?php } // end if
// Use reset to restore original query.
wp_reset_postdata();
}
?>
</div><!-- blog-main-content-->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Please what do I do
Based on your comment above, you are missing a template file for your posts page. In your current configuration, the posts loop will be displayed on all pages of your website since you only have an index.php file. You should create a single.php template to display your single blog posts.
Here is the WordPress template hierarchy for reference: https://developer.wordpress.org/themes/basics/template-hierarchy/
I have to add some simple HTML to the homepage of a client's WordPress website. At first, I added the code to the header.php and everything looked and worked how it should; but, then I realised that it was showing on every page when I just need it on the home page.
So, I tried adding the same HTML after the get_header in the homepage.php and then in the index.php but nothing shows at all when I add the code to these pages.
No matter where I put the HTML in homepage.php or index.php it will not show. I'm new to WordPress as you have no doubt gathered.
Do I need to make a template or use some code to introduce the HTML in either of these two pages? Why does it show in the header.php?
I tried using with no joy:
if ( is_home() ) {
The home page code is here if it helps:
<?php
/**
Template Name: Homepage
*
*/
get_header(); ?>
<?php $general_options = get_option( 'meanthemes_theme_general_options' ); ?>
<?php $content_options = get_option ( 'meanthemes_theme_content_options' ); ?>
<?php if( isset( $general_options[ 'hide_slider' ] ) ) {
// do nothing
} else {
?>
<section class="hero flexslider">
<article class="wrapper">
<div class="flex-container"></div>
<ul class="slides">
<?php
$bannerPortfolio = $general_options[ 'swap_slider' ];
if(!$bannerPortfolio) {
query_posts( array ( 'posts_per_page' => 3 ) );
while ( have_posts() ) : the_post();
?>
<li>
<h2>
<?php the_title(); ?>
</h2>
<div>
<?php echo excerpt_clip(get_the_excerpt(), '28'); ?> <?php _e('[...]','meanthemes'); ?>
</div>
<time class="time" datetime="<?php the_time('Y-m-d', '', ''); ?>"><?php the_time('jS M Y') ?></time>
</li>
<?php endwhile; wp_reset_query(); ?>
<?php
} else {
?>
<?php
query_posts( array( 'post_type' => 'portfolio', 'order' => 'desc', 'posts_per_page' => '3' ) );
?>
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<li>
<hgroup>
<h2>
<?php the_title(); ?>
</h2>
<div>
<?php echo excerpt_clip(get_the_excerpt(), '48'); ?> <?php _e('[...]','meanthemes'); ?></div>
</hgroup>
</li>
<?php endwhile; ?>
<?php } ?>
</ul>
</article><!-- / article.wrapper -->
</section>
<script>
jQuery(window).load(function() {
jQuery('.flexslider').flexslider({
animation: "fade", // animation type fade or slide
slideshowSpeed: <?php echo sanitize_text_field( $general_options ['slider_timer'] ); ?>, // sections between transitions
directionNav: true, // show previous and back
controlNav: false,
controlsContainer: '.flex-container'
});
});
</script>
<?php } ?>
<?php if( $general_options[ 'show_portfolio' ] ) { ?>
<section class="wrapper portfolio">
<article>
<hgroup>
<h2><?php echo balanceTags( $content_options['we_do'] ); ?></h2>
</hgroup>
<div><?php echo balanceTags( $content_options['we_do_summary'] ); ?></div>
</article>
<?php
query_posts( array( 'post_type' => 'portfolio', 'posts_per_page' => '4', 'orderby' => 'date', 'order' => 'desc' ) );
?>
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<aside>
<?php the_post_thumbnail('portfolio-thumb'); ?>
<hgroup>
<h3><?php the_title(); ?></h3>
</hgroup>
<div><?php echo excerpt_clip(get_the_excerpt(), '14'); ?><?php _e('[...]','meanthemes'); ?></div>
</aside>
<?php endwhile; wp_reset_query(); ?>
</section>
<?php } ?>
<script>
jQuery(document).ready(function() {
jQuery('body').addClass("home");
});
</script>
<?php get_footer(); ?>
Howlin's example should work. Another solution is to create a front-page.php in the theme-directory, copy the content from the page.php to it, and add your specific HTML-Code for the homepage (frontpage).
Visit http://codex.wordpress.org/Template_Hierarchy to understand which template is invoked in which case.
Visit http://codex.wordpress.org/Conditional_Tags for Conditional Tags, which you can use e.g. in theheader.php
You might need to try is_front_page instead.
if(is_front_page()){
is_home works if you have blog posts displaying on the homepage and is_front_page if the homepage is set as a static page.
I have this code:
<?php $q = new WP_Query(array(
'post_type' => 'oferty'
));
?>
<?php while ($q -> have_posts()) : $q -> the_post(); ?>
<!-- .post | id: <? echo $post->ID; ?> -->
<article <?php post_class() ?> id="post-<?php the_ID(); ?>">
<div class="entry">
<h1><?php the_title(); ?></h1>
<small><?php echo get_field('bank'); ?></small>
<?php the_content(); ?>
</div>
<?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumbnail' ); ?>
<?php if($thumb) : ?>
<div class="bankimg" style="background-image: url('<?php echo $thumb[0];?>')"></div>
<?php endif; ?>
<div class="clear"></div>
</article>
<!-- /.post | id: <? echo $post->ID; ?> -->
<?php endwhile; wp_reset_query(); ?>
<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?>
It uses wp_query to list all the posts from post type oferty. I set in WordPress options limit of posts to 2 and it works - but no pagination shows up. I tried WP PageNavi, WP Pagination and normal WordPress' prev/next linsk.
Take a look at the pagination parameters when querying for custom post types:
https://codex.wordpress.org/Class_Reference/WP_Query#Pagination_Parameters
Specifically, try this:
$q = new WP_Query(array(
'post_type' => 'oferty',
'posts_per_page' => 2
));
I've been on a long google search trying to find the solution to this... I am creating a cv manager theme using a WordPress install to control content. I have managed to organise all WP posts in categories but would also like to list those posts in year groupings. Currently I have this:
<?php // Categories
$cvm_cat_args = array('orderby' => 'name', 'order' => 'ASC' );
$categories = get_categories($cvm_cat_args); ?>
<?php foreach($categories as $category) : ?>
<?php // Posts in category
$cvm_post_args = array( 'showposts' => -1, 'category__in' => array($category->term_id), 'caller_get_posts'=>1, 'order' => 'ASC' );
$posts = get_posts($cvm_post_args); ?>
<?php if ($posts) : ?>
<h1><?php echo $category->name ?></h1>
<?php foreach($posts as $post) : ?>
<?php setup_postdata($post); ?>
<h3><?php the_title(); ?></h3>
<small><?php the_time(); ?></small>
<?php the_excerpt() ?>
<?php endforeach; ?>
<?php endif; ?>
<?php endforeach; ?>
I'm stuck on how to display the posts in year order within the category so that the output would be something like this:
<h1>Category Name 1</h1>
<h2>2010</h1>
<h3>Post name 1</h3>
<p>Excerpt...</p>
<h3>Post name 2</h3>
<p>Excerpt...</p>
<h2>2009</h1>
<h3>Post name 3</h3>
<p>Excerpt...</p>
<h3>Post name 4</h3>
<p>Excerpt...</p>
<h1>Category Name 2</h2>
etc
Any help would be mightily appreciated.
Thanks!
<?php $year = ''; ?>
<?php foreach($posts as $post) : ?>
<?php setup_postdata($post); ?>
<?php if (get_the_time('Y') != $year): ?>
<?php $year = get_the_time('Y'); ?>
<h2><?php echo $year; ?></h2>
<?php endif; ?>
<h3>Post name 1</h3>
<p>Excerpt...</p>
<h3>Post name 2</h3>
<p>Excerpt...</p>
<?php endforeach; ?>