当前位置:首页 > 未命名 > 正文内容

How to post to different page on a blog base on LNMP and wordpress

u3blog8年前 (2016-02-24)未命名233

Request:

Now we have a blog base on LNMP and Wordpress, we have two page named "english" and "chinese". I want to click on the English display categories of articles in English and Chinese page in the same way.

step1:Need to create your own page templatee, directly copy a page.php file below the theme folder in the server and add below code in the file head

<?php
/*
Template Name: Your template name
*/
get_header(); ?>
Save it.

problem0:Cant see the template on page edit after we save it.

solution:Switch to other themes and then switch back.

problem1:In the interface of the theme is only one theme, there is no other theme has been installed.

solution: Because we use lnmp, for security reasons,it closed scandir method,please open it at php.ini file. You can find how to do it by google.

Now, we can see our own templae, choose and apply it.

step2:Let's associated with the page template with the corresponding category

By click on the category in the background,can get tag_id value in the url,remember the value of different categories. Then again open our custom template find out
<?php if (have_post()):?>
This line, add content in front of it
<?php
$catID = 0;
if (is_page('EnglishBlog')) {
  $catID=3;   
} elseif (is_page('ChineseBlog')) {
  $catID=2;
}//Your page name and ID in this setting

if ($catID) {
   $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
   query_posts("cat=$catID&amp;paged=$paged");
} ?>
then save it Now,you can by clicking on the page to view the different categories of the post.

扫描二维码推送至手机访问。

版权声明:本文由u3blog发布,如需转载请注明出处。

本文链接:https://u3blog.xyz/?id=216

分享给朋友:

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。