wordpress根据条件不同调用不同的模板,这个代码应该在哪个文件写...
分类页选择不同的模板,在category.php中添加如下代码:}elseif(is_category(array(10))){include(TEMPLATEPATH . '/cat-news.php');//填写对应的模板名}else{include(TEMPLATEPATH . '/cat-news.php');//以上都不在ID范围内就选择这个} ?>;详情页选择模板,在single.php文件中添加如下代码:跟上面的原理是一样的,根据需要添加对应的elseifinclude(TEMPLATEPATH .'/single-news.php');}else{include(TEMPLATEPATH .'/single-pro.php');}?>;那么page页面如何做呢?原理也是一样的,如果扩福你不填参数表示只要是page页面都会选择对应的模板也可以添加array()数组if ( is_page() ){ include(TEMPLATEPATH .'/page-about.php'); } else{ include(TEMPLATEPATH .'/page-about.php'); }?>;不懂请追问
SpringMVC 整合 kindeditor 我是新手 怎么也整不明白了
展开全部 @RequestMapping(value = "/Kindeditor/uploadFile", method = RequestMethod.POST) public void uploadFile(HttpServletRequest request, HttpServletResponse response) throws Exception { PrintWriter writer = response.getWriter(); try { // 文件保存目录路径 String savePath = request.getSession().getServletContext().getRealPath("/") + "upload" + File.separatorChar + "products" + File.separatorChar; String saveUrl = request.getContextPath()+ File.separatorChar + "upload" + File.separatorChar + "products" + File.separatorChar; // 定义允许上传的文件扩展名 HashMap extMap = new HashMap(); extMap.put("image", "gif,jpg,jpeg,png,bmp"); // 最大文件大小 long maxSize = 1000000; response.setContentType("text/html; charset=utf-8"); if (!ServletFileUpload.isMultipartContent(request)) { writer.println(getError("请选择文件。
")); return; } File uploadDir = new File(savePath); // 判断文件夹是否存在,如果不存在则创建文件夹 if (!uploadDir.exists()) { uploadDir.mkdirs(); } // 检查目录写权限 if (!uploadDir.canWrite()) { writer.println(getError("上传目录没有写权限。
")); return; } String dirName = request.getParameter("dir"); if (dirName == null) { dirName = "image"; } if (!extMap.containsKey(dirName)) { writer.println(getError("目录名不正确。
")); return; } MultipartHttpServletRequest mRequest = (MultipartHttpServletRequest) request; Map fileMap = mRequest.getFileMap(); String fileName = null; for (Iterator> it = fileMap.entrySet().iterator(); it.hasNext();) { Map.Entry entry = it.next(); MultipartFile mFile = entry.getValue(); fileName = mFile.getOriginalFilename(); // 检查文件大小 if (mFile.getSize() > maxSize) { writer.println(getError("上传文件大小超过限制。
")); return; } String fileExt = fileName.substring(fileName.lastIndexOf(".")+1); if (!Arrays. asList(extMap.get(dirName).split(",")).contains(fileExt)) { writer.println(getError("上传文件扩展名是不允许的扩展名。
\n只允许" + extMap.get(dirName) + "格式。
")); return; } UUID uuid = UUID.randomUUID(); String path = savePath + uuid.toString() +"."+ fileExt; saveUrl = saveUrl + uuid.toString() +"."+ fileExt; BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(path)); FileCopyUtils.copy(mFile.getInputStream(), outputStream); JSONObject obj = new JSONObject(); obj.put("error", 0); obj.put("url", saveUrl); writer.println(obj.toString()); } } catch (ServiceException serviceException) { writer.println(getError(ApplicationContextUtil.getMessage(serviceException))); return; } } private String getError(String message) { JSONObject obj = new JSONObject(); obj.put("error", 1); obj.put("message", message); return obj.toString(); } [html] view plain copy print?" type="text/css"/> " type="text/css"/> " type="text/javascript"> " type="text/javascript"> " type="text/javascript"> [html] view plain copy print? [javascript] view plain copy print?KindEditor.ready(function(K) { var introduction = K.create('#introduction',{ items:[ 'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste', 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript', 'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/', 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage', 'table', 'hr', 'emoticons', 'pagebreak', 'anchor', 'link', 'unlink', '|', 'about' ], uploadJson : '${ctx}/backoffice/Kindeditor/uploadFile.do', afterCreate : function() { var self = this; K.ctrl(document, 13, function() { self.sync(); document.forms['inputForm'].submit(); }); K.ctrl(self.edit.doc, 13, function() { self.sync(); document.forms['inputForm'].submit(); }); }}); introduction.readonly();//只读 });
什么意思
展开全部 archive.php不能那样调的。
如果你想要做多个archive模板,然后分别调用采用这样的方法: 1、新建archive-A.php archive-B.php archive-C.php 2、清空archive.php 然后复制加入下面的判断调用代码,并保存 备注:上面的“4,8,9”是分类目录的ID值。
那段代码表示:根据不同的分类编号判断调用不同的archive模板。
希望能帮到你。
如何在Wordpress中自定义PHP页面并操作数据库
展开全部 1. 尝试设置一个页面模板1)拷贝一个index.php并改名为其它名,如list.php;2)在list.php页面最顶部添加以上两步就可以创建一个页面模板了,修改并保存好这个文件后,创建一个新页面或者修改已存在的页面。
在右下边有个“页面模板”的面板,在下拉菜单中选中“友链”后保存就可以了。
然后在页面中添加任何内容,包括html代码就可以显示了。
可是我的需求是要自己完成PHP代码获取数据并展示,它不能这么做。
2. 调用 WordPress 的 API实现URL正确跳转这种方法的自由度较高,并且可以创建非WordPress格式的URL。
比如我们要把 www.example.com/list 转交给主题文件夹下的 /custom/list.php 来处理,就可以用这种方式来处理。
这种方法用到 template redirect 钩子,template redirect 是 WordPress 在预处理好所有参数设置之后决定调用主题模板的时候调用的。
在functions.php模板函数文件中添加以下实例代码:function loadCustomTemplate($template) { global $wp_query; if(!file_exists($template))return; $wp_query->is_page = true; $wp_query->is_single = false; $wp_query->is_home = false; $wp_query->comments = false; // if we have a 404 status if ($wp_query->is_404) { // set status of 404 to false unset($wp_query->query["error"]); $wp_query->query_vars["error"]=""; $wp_query->is_404=false; } // change the header to 200 OK header("HTTP/1.1 200 OK"); //load our template include($template); exit;}function templateRedirect() { $basename = basename($_SERVER['REQUEST_URI'], '?' . $_SERVER['QUERY_STRING']); loadCustomTemplate(TEMPLATEPATH.'/custom/'."/$basename.php");}add_action('template_redirect', 'templateRedirect');这样就实现了 WordPress 查找 /custom 文件夹下的 php 文件,并且将相匹配的 URL 请求转交给对应的 php 文件来处理的效果,与此同时,这个 php 文件还保持了对 WordPress API 的调用,因此留给我们的空间非常大。
接下来就可以在 /custom 文件夹下自定义一个list.php文件然后通过链接www.example.com/list访问。
3. 添加页面内容,获取自定义数据库/表中的内容然后就可以根据需要自己需要来实现自己想要的功能,这里需要有以下几点要处理:1)如何操作数据库WordPress提供了一个全局变量$wpdb,并将其实例化为wpdb类的对象。
这样我们就可以直接使用$wpdb来调用所有的数据库操作函数。
通过这个$wpdb对象,我们可以对WordPress数据库进行任何操作,包括建表、查询、删除、更新等。
使用$wpdb->get_results实现执行sql语句操作数据库,并获取结果。
global $wpdb;$sql= "SELECT * FROM ".$wpdb->prefix.table;$a = $wpdb->get_results($sql);2)使用wordpress的样式通过F12查看首页代码就可以发现只要使用对应的class样式就能轻松让页面统一规整。
那么就把对应的html添加到自定义PHP页面中即可。
3)利用wordpress的规则轻松实现翻页wordpress已经默认支持翻页,格式如:www.example.com/list?page=$1,只要在自定义的页面里面定义好每页返回正确的内容就好啦。
4. 设置nginx rewrite规则可读性强的URL一定不能是www.example.com/list?page=2这样的格式,对爬虫也不友好,那就需要配置好rewrite规则,我使用的是nginx的配置为:rewrite ^(.*)/indexed/page/([0-9]+)$ $1/indexed?page=$2 last;到现在为止,离成功只有一步之遥了,那就是新建一个页面, 大功告成!
wordpress主题里面调用archive.php的问题
你理解错了吧,category是分类的意思,你那段代码是single的页面,估计是不同分类下的文章显示不同的样式。
你上面所写的in_category('3')是,在分类ID为3的文章,将调用的single-pro.php页面样式模板。
in_category('42')则为,如果文章是在分类ID为42下的,将调用single-news.php的页面样式模板。
else ,否则,(分类3和42外的文章),都调用single-all.php页面样式模板作为single.php。
wordpress里需要用到的一点php中 if else 语句的问题,求教。
。
。
展开全部 1、需要大家新建一个搜索页面,将它命名为:searchform.php2、直接用DW打开searchform.php,将以下代码一会补充复制到searchform.php中。
3、复制添加网站主题里边的wordpress 分类模板目录,可以是文章的列表目录,也可以是产品图片列表目录,然后更名为search.php,才能实现搜索功能。
4、选择搜索框显示的页面位置,并在相应的位置添加搜索框调用代码: 按照以上步骤全部完成之后,就可以在自己的网站上实现搜索功能了。
...
转载请注明出处51数据库 » templatepath wordpre