php中 $wp
$limit = get_option('posts_per_page');$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;query_posts('showposts=' . $limit=7 . '&paged=' . $paged);//limit变量控制最新文章数量$wp_query->is_archive = true; $wp_query->is_home = false;?>ID)) : ?>
wordpress首页如何调用最新文章
第一种方法WordPress最新文章的调用可以使用一行很简单的模板标签wp_get_archvies来实现. 代码如下:(显示10篇最新更新文章)或后面这个代码显示你博客中最新的20篇文章,其中format=custom这里主要用来自定义这份文章列表的显示样式。
具体的参数和使用方法你可以参考官方的使用说明- wp_get_archvies。
(fromat=custom也可以不要,默认以UL列表显示文章标题。
)补充: 通过WP的query_posts()函数也能调用最新文章列表, 虽然代码会比较多一点,但可以更好的控制Loop的显示,比如你可以设置是否显示摘要。
具体的使用方法也可以查看官方的说明。
第二种方法调用最新文章:(直接在想要呈现的位置放上以下代码即可)$limit = get_option('posts_per_page');$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;query_posts('showposts=' . $limit=7 . '&paged=' . $paged);$wp_query->is_archive = true; $wp_query->is_home = false;?>ID)) : ?>
wordpress如何获取当前文章的id,要求写一个函数在function里面调用 ...
//The args$args = array('cat' =>61 //这是分类ID,也可以用array给一组ID);// The Result$naruco= new WP_Query( $args );if ( $naruco->have_posts() ) {// The Loopwhile ( $naruco->have_posts() ) : $naruco->the_post();echo '';$post_ID = get_the_ID(); //这就是文章的ID了。
$post_content = get_the_content(); //文章内容,至于怎么截取一定长度的字数,百度一下到处都是啦。
echo '';endwhile;}else {echo 'no posts in current category!';}?>说的全在注释里了。
wordpress怎样调用文章中的第一张图片
方法/步骤这里需要用到phpMyAdmin,虚拟机一般都有装这个功能,如果是自己的服务器或者本地可以下载安装一个这个软件,它是mysql数据库中最优秀的管理软件。
进入phpmyadmin后找到你的wordpres数据库,点击如图画圈的地方修改字段。
这里你会看到之前你的管理账号的密码user_pass字段,因为是经过加密的密码所以你不能直接修改成十进制的普通密码。
点击画圈的地方修改。
把这段加密的密码修改成“5d41402abc4b2a76b9719d911017c592”点击执行。
(引号里面的)这里就会提示你修改成功。
然后你用“hello”登陆后台就进去了,记得在后台修改下密码哦,别再忘记了。
如何用纯代码方法实现WordPress面包屑导航效果
1、层级较深的网站,面包屑导航适合层级较深的网站,如果只有一级分类的话,通过主导航就可以起到快速定位的作用。
比如“豆瓣网”类型扁平构架的网站就没有使用面包屑导航的作用。
2、独立不交叉的网站机构,由于面包屑网站导航路径是线性结构的,因此网站内容必须划分的非常清晰,且不存在交叉;否则,面包屑导航的路径就不是唯一的,同一分类可能出现在不同的路径中,让用户感到困惑。
在wordpress中添加面包屑导航的话,可以直接使用插件来实现,不过很多站长都不喜欢用插件,还是认为如果能用代码解决的话是最理想的。
我最近也找了一些关于面包屑导航的资料。
下文中就有详细解决怎么用代码来实现wordpress面包屑导航:一、在wordpress博客当前主题的functions.php文件(没有就创建一个)中添加以下代码://面包屑导航 function get_breadcrumbs() { global $wp_query; if ( !is_home() ){ // Start the UL echo ''; // Add the Home link echo ''. get_bloginfo('name') .''; if ( is_category() ) { $catTitle = single_cat_title( "", false ); $cat = get_cat_ID( $catTitle ); echo " ? ". get_category_parents( $cat, TRUE, " ? " ) .""; } elseif ( is_archive() && !is_category() ) { echo " ? Archives"; } elseif ( is_search() ) { echo " ? Search Results"; } elseif ( is_404() ) { echo " ? 404 Not Found"; } elseif ( is_single() ) { $category = get_the_category(); $category_id = get_cat_ID( $category[0]->cat_name ); echo ' ? '. get_category_parents( $category_id, TRUE, " ? " ); echo the_title('','', FALSE) .""; } elseif ( is_page() ) { $post = $wp_query->get_queried_object(); if ( $post->post_parent == 0 ){ echo " ? ".the_title('','', FALSE).""; } else { $title = the_title('','', FALSE); $ancestors = array_reverse( get_post_ancestors( $post->ID ) ); array_push($ancestors, $post->ID); foreach ( $ancestors as $ancestor ){ if( $ancestor != end($ancestors) ){ echo ' ? '. strip_tags( apply_filters( 'single_post_title', get_the_title( $ancestor ) ) ) .''; } else { echo ' ? '. strip_tags( apply_filters( 'single_post_title', get_the_title( $ancestor ) ) ) .''; } } } } // End the UL echo ""; } } 二、在显示面包屑导航的位置添加以下调用代码:if (function_exists('get_breadcrumbs')){ get_breadcrumbs(); } ?> 三、在主题的css样式文件中添加以下样式代码:ul.breadcrumbs {list-style: none; font-size:12px;} ul.breadcrumbs li {float: left; margin-right:5px;}
怎样制作wordpress的面包屑导航
如果是新手, 建议用其他Wordpress 的插件。
例如Yoast SEO 或者 WP SEO 他们都有加面包屑的功能, 如果不想加插件, 可以把以下加进function.php // Breadcrumbs function custom_breadcrumbs() { // Settings $separator = '>'; $breadcrums_id = 'breadcrumbs'; $breadcrums_class = 'breadcrumbs'; $home_title = 'Homepage'; // If you have any custom post types with custom taxonomies, put the taxonomy name below (e.g. product_cat) $custom_taxonomy = 'product_cat'; // Get the query & post information global $post,$wp_query; // Do not display on the homepage if ( !is_front_page() ) { // Build the breadcrums echo ''; // Home page echo '' . $home_title . ''; echo ' ' . $separator . ' '; if ( is_archive() && !is_tax() && !is_category() && !is_tag() ) { echo '' . post_type_archive_title($prefix, false) . ''; } else if ( is_archive() && is_tax() && !is_category() && !is_tag() ) { // If post is a custom post type $post_type = get_post_type(); // If it is a custom post type display name and link if($post_type != 'post') { $post_type_object = get_post_type_object($post_type); $post_type_archive = get_post_type_archive_link($post_type); echo 'labels->name . '">' . $post_type_object->labels->name . ''; echo ' ' . $separator . ' '; } $custom_tax_name = get_queried_object()->name; echo '' . $custom_tax_name . ''; } else if ( is_single() ) { // If post is a custom post type $post_type = get_post_type(); // If it is a custom post type display name and link if($post_type != 'post') { $post_type_object = get_post_type_object($post_type); $post_type_archive = get_post_type_archive_link($post_type); echo 'labels->name . '">' . $post_type_object->labels->name . ''; echo ' ' . $separator . ' '; } // Get post category info $category = get_the_category(); if(!empty($category)) { // Get last category post is in $last_category = end(array_values($category)); // Get parent any categories and create array $get_cat_parents = rtrim(get_category_parents($last_category->term_id, true, ','),','); $cat_parents = explode(',',$get_cat_parents); // Loop through parent categories and store in variable $cat_display $cat_display = ''; foreach($cat_parents as $parents) { $cat_display .= ''.$parents.''; $cat_display .= ' ' . $separator . ' '; } } // If it's a custom post type within a custom taxonomy $taxonomy_exists = taxonomy_exists($custom_taxonomy); if(empty($last_category) && !empty($custom_taxonomy) && $taxonomy_exists) { $taxonomy_terms = get_the_terms( $post->ID, $custom_taxonomy ); $cat_id = $taxonomy_terms[0]->term_id; $cat_nicename = $taxonomy_terms[0]->slug; $cat_link = get_term_link($taxonomy_terms[0]->term_id, $custom_taxonomy); $cat_name = $taxonomy_terms[0]->name; } // Check if the post is in a category if(!empty($last_category)) { echo $cat_display; echo 'ID . '">ID . '" title="' . get_the_title() . '">' . get_the_title() . ''; // Else if post is in a custom taxonomy } else if(!empty($cat_id)) { echo '' . $cat_name . ''; echo ' ' . $separator . ' '; echo 'ID . '">ID . '" title="' . get_the_title() . '">' . get_the_title() . ''; } else { echo 'ID . '">ID . '" title="' . get_the_title() . '">' . get_the_title() . ''; } } else if ( is_category() ) { // Category page echo '' . single_cat_title('', false) . ''; } else if ( is_page() ) { // Standard page if( $post->post_parent ){ // If child page, get parents $anc = get_post_ancestors( $post->ID ); // Get parents in the right order $anc = array_reverse($anc); // Parent page loop if ( !isset( $parents ) ) $parents = null; foreach ( $anc as $ancestor ) { $parents .= '' . get_the_title($ancestor) . ''; $parents .= ' ' . $separator . ' '; } // Display parent pages echo $parents; // Current page echo 'ID . '"> ' . get_the_title() . ''; } else { // Just display current page if not parents echo 'ID . '">ID . '"> ' . get_the_title() . ''; } } echo ''; } }
wordpress jquery加载 如何实现?是否有插件?
下面是调用jQuery的几种方法:1.自己从网上下载挂在自己网站中。
/js/jquery.js”></script>2.直接调用谷歌 Google 的 API库</script>3.直接调用WP自带的 jQuery但要注意的是: wp_enqueue_script('jquery'); 必需加在 wp_head(); 的前面,而且 js 的写法是:jQuery(document).ready(function($) {// $() will work as an alias for jQuery() inside of this function});这样 jQuery() 包里的所有 $() 才能被正确识别.大家的习惯写法也:$(document).ready(function() { … }); 需要改为 jQuery(document).ready(function($) { … });这是为了 noConflict();另外, 把全部简写的“$” 还原回,使用“jQuery” 也行.
怎么修改WordPress后台登录地址
使用代码如果你不喜欢插件,可以将下面的代码添加到当前主题的 functions.php 文件:代码如下 复制代码 //保护后台登录add_action('login_enqueue_scripts','login_protection');function login_protection(){if($_GET['word'] != 'press')header('Location: http://www.你的网站地址.com/');}这样一来,后台登录的唯一地址就是 http://你的网站地址/wp-login.php?word=press,如果不是这个地址,就会自动跳转到 http://www.wpdaxue.com/ ,不信你试试!你可以修改第 4 行的 Word、press 和 http://www.你的网站地址.com/ 这三个参数。
另一种修改后台地址的方法首先给wp-admin目录改名,比如我改成shunix然后在.htaccess里加上如下内容:代码如下 复制代码 RewriteEngine OnRewriteBase /RewriteCond %{REQUEST_URI} wp-admin/RewriteCond %{QUERY_STRING} !这里来个复杂字符串(数字英文横杠下划线组成)RewriteRule .*.php [F,L]RewriteCond %{QUERY_STRING} !与上面的那个密码相同RewriteRule ^shunix/(.*) wp-admin/$1?%{QUERY_STRING}&与上面的那个密码相同这个.htaccess实现了URL的重写,禁止访问wp-admin下的所有.php文件,访问/shunix 的话会直接替换成/wp-admin下的对应文件。
也就是说访问/shunix与访问wp-admin的结果是一样的,但是访问wp-admin则行不通。
如果实在闲的蛋疼,就是要访问wp-admin目录,那么可以这样访问:http://你的网站地址/wp-admin?你设置的那个密码更名完成,但是会有一些问题需要修改部分文件。
因为wp-admin被禁止访问,而部分功能还直接调用wp-admin的.php文件。
这导致上传功能将不能使用;自动保存,自定义字段都无法使用。
下面要做的就是修改几个重要文件,重新恢复这些功能:查找wp-admin/includes/media.phpwp-includes/script-loader.phpwp-includes/link-template.php三个文件中所有的wp-admin,换成shunix
转载请注明出处51数据库 » wp_query wordpress