我写了一个短代码,以给定的语言显示6个wordpres条目。
此循环的工作方式如下:如果浏览器的语言为波兰语,则以波兰语显示类别;如果浏览器的语言不同,则以英语显示帖子。
此解决方案已经使用了几年,但是自上次更新以来,Polylang一直没有使用。如果浏览器语言是例如? lang = es没有显示帖子。
<?php
define('WP_USE_THEMES', false);
require('../wp-load.php');
?>
<?php
$lang = $_GET['lang'];
if ($lang == 'pl'){
query_posts('cat=65&post_type=post&post_status=publish&showposts=6');
$title = "Aktualności i Wydarzenia";}
else {
query_posts('cat=67&post_type=post&post_status=publish&showposts=6');
$title = "News and Events";}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="themes/suffice-child/style.css">
<link rel="stylesheet" type="text/css" href="themes/suffice/style.css">
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,700&subset=latin-ext" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.blog-title{
margin: 60px 0 0px 0;
text-align: center;
font-weight: 500;
}
a:visited{
color:#424143;
}
.post{
margin-top: 60px;
}
h3 {
margin-bottom: 10px;
}
p.post-date{
margin: 0px;
font-style: italic;
}
p.post-summary{
margin: 10px 0 0 0;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<!--right-->
<div class="col-md-12">
<h2 class="blog-title"><?php echo "$title"; ?></h2>
<?php
$postCounter = 0;
?>
<div class="row">
<?php
/*
Start the loop
*/
while (have_posts()) : the_post();
?>
<?php
$postCounter += 1;
?>
<!-- This div serves as the template for each post returned within the loop -->
<div class="col-sm-6 col-md-4">
<article class="post blog-post">
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<div class="post-info">
<p class="post-date date"><?php echo the_time('j F Y'); ?></p>
<p class="post-summary"><?php the_excerpt();?></p>
</div>
</article>
</div>
<?php
/*
Check whether the counter has hit 3 posts.
If true, close the "row" div. Also reset the $startRow variable so that before the next post, a new "row" div is being created. Finally, reset the counter to track the next set of three posts.
If false, do nothing.
*/
if ( ($postCounter % 2) == 0 ) {
echo '<div class="clearfix visible-sm-block"></div>';
}
if ( ($postCounter % 3) == 0 ) {
echo '<div class="clearfix visible-md-block"></div>';
echo '<div class="clearfix visible-lg-block"></div>';
}
?>
<?php endwhile; ?>
</div>
</div><!-- END OF COL-MD-9 -->
</div><!-- END OF ROW -->
</div><!-- END OF CONTAINER -->