• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

基于wordpress主题制作的具体实现步骤_php技巧

php 搞代码 4年前 (2022-01-26) 30次浏览 已收录 0个评论
<?php<BR>/*<BR>在根目录 -> wp-content -> themes 下创建mytheme文件夹用来存放创建新主题模板</P><P>在mytheme目录下创建 index.php ,style.css 两个文件,在wp后台 外观->主题 中就可以看到刚创建的主题</P><P>打开style.css文件输入<BR>*/<BR>?><BR>/*<BR>Theme Name: 这里填主题名称<BR>Theme URI: 这里填主题介绍的网址,没有就填你的博客网址吧<BR>Description:这里填主题的简短介绍<BR>Author: 作者名<BR>Author URI: 作者的网址<BR>Version: 版本号<BR>Tags: 标签,多个用半角逗号隔开<BR>*/<BR><?php<BR>/*<BR>在后台主题管理中即可看到主题相关信息,css中主题信息内容必须用注释符号括起来</P><P>找一个300*225的png图片,命名为 screenshot.png 放在主题目录下(mytheme文件夹中),在主题管理页中即可看到新建主题的预览图片</P><P>//==================================================header================================================================<BR>可以把网站相同头内容放在一个头文件中,在主题目录下新建 header.php 文件向其中输入输入 统一的头部内容<BR>在 index.php 或想调用该header.php页面的页面中 输入<BR>*/</P><P>get_header(); //get_header()就相当于将header.php中的代码拷贝到当前的php文件</P><P>/*<BR>在主题管理页面,该主题实时预览中,默认打开的 index.php 页面中即可引入 header.php 页面的内容<BR>header.php 将会被所有的模板页面(主页、分类页、页面、标签页等)所包含,所以 header.php 中代码应该是动态的。<BR>不同页面的title<em>8本文来源gao.dai.ma.com搞@代*码(网$</em><pre>搞代gaodaima码

都是不一样,而且title的设置还会直接影响到SEO的效果,所以这里应该谨慎设置。下面提供一种SEO优化的title写法,
在header.php页面添加
*/
?>
<BR><?php<BR>if (is_home ()) { // is_home() 当前页面为主页时返回true<BR> bloginfo ( ‘name’ ); // 返回站点标题<BR> echo ” – “;<BR> bloginfo ( ‘description’ ); // 返回站点副标题,站点描述<BR>} elseif (is_category ()) { // is_category() 当前页面为分类页时返回true<BR> single_cat_title ();<BR> echo ” – “;<BR> bloginfo ( ‘name’ );<BR>} elseif (is_single () || is_page ()) { // is_single() 当前页面为单文章页时返回true 。 is_page() 当前页面为单页面时返回true<BR> single_post_title ();<BR>} elseif (is_search ()) { // is_search() 当前页面为搜索页时返回true<BR> echo “搜索结果”;<BR> echo ” – “;<BR> bloginfo ( ‘name’ );<BR>} elseif (is_404 ()) { // is_404() 当前页面为404页时返回true<BR> echo ‘页面未找到!’;<BR>} else {<BR> wp_title ( ”, true );<BR>}<BR>?><BR>
<?php
/*
以上添加的php代码运用了条件判断,针对不同的页面采用不同title
在 header.php 页面中添加默认 style.css 文件
*/
?>
<link rel=”stylesheet” href=”<?php bloginfo(‘stylesheet_url’); ?>” type=”text/css” media=”screen” />
<?php
/*
bloginfo(‘stylesheet_url’);返回的是主题默认style.css文件绝对网址路径,如
http://localhost/wordpress/wp-content/themes/myTheme/style.css
bloginfo(‘template_url’);返回的是主题目录的绝对网址路径,可以用来模板中连接样式图片,如
http://localhost/wordpress/wp-content/themes/mytheme
添加 pingback 通告功能,在header.php页面 标签中里面添加代码:
*/
?>
<link rel=”pingback” href=”<?php bloginfo(‘pingback_url’); ?>” />
<?php
/*
添加订阅feed链接,在header.php页面 标签中添加:
*/
?>
<link rel=”alternate” type=”application/rss+xml” title=”RSS 2.0 – 所有文章” href=”<?php echo get_bloginfo(‘rss2_url’); ?>” />
<link rel=”alternate” type=”application/rss+xml” title=”RSS 2.0 – 所有评论” href=”<?php bloginfo(‘comments_rss2_url’); ?>” />
<?php
/*
添加wp_head,有些插件需要在网页头部添加一些js或css,要让这些插件能够正常的工作,也让主题有更好的兼容性,应该添加wp_head()函数
header.php 页面 标签中添加
*/
?>

<?php wp_head(); //用于包含WordPress程序输出头部信息 ?>

<?php
/*
显示菜单栏,这里只在菜单栏中列出分类页和page页面,可以根据喜好来列出想要的。header.php中
*/
?>


<?php
//==================================================footer================================================================
/*
footer.php与header.php差不多,写这个文件的目的也是为了精简代码,提高代码的重用性。
在主题目录中创建 footer.php ,在 index.php 或想调用该footer.php页面的页面中使用
*/
get_footer();//功能和get_header()类似
/*
在footer.php页面添加 wp_footer提高兼容性
*/
wp_footer();
/*
wp_footer()和wp_head()差不多,都是用于提高主题兼容性,毕竟有很多插件要在页脚输出一些东西才能正常工作。
*/
//==================================================sidebar================================================================
/*
在主题目录下新建 sidebar.php 页面,在 index.php 或想调用该sidebar.php页面的页面中添加
*/
get_sidebar();
/*
调用 sidebar.php 页面内容
为使WordPress后台 -> 外观 -> 小工具,可以正常地拖动小工具到侧边栏
在 sidebar.php 页面的列表格式应按如下举例格式
*/
?>


<?php
if (! function_exists ( ‘dynamic_sidebar’ ) || ! dynamic_sidebar ( ‘First_sidebar’ )) ://First_sidebar为widget名称,要和functions.php中对应的widget name相同
?>

分类目录



    <?php wp_list_categories(‘depth=1&title_li=&orderby=id&show_count=0&hide_empty=1&child_of=0’); ?>


<?php endif; ?>


<?php
if (! function_exists ( ‘dynamic_sidebar’ ) || ! dynamic_sidebar ( ‘Second_sidebar’ )) :
?>

最新文章



    <?php
    $posts = get_posts ( ‘numberposts=6&orderby=post_date’ );
    foreach ( $posts as $post ) {
    setup_postdata ( $post );
    echo ‘

  • ‘ . get_the_title () . ‘
  • ‘;
    }
    $post = $posts [0];
    ?>


<?php endif; ?>


<?php
if (! function_exists ( ‘dynamic_sidebar’ ) || ! dynamic_sidebar ( ‘Third_sidebar’ )) :
?>

标签云



搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:基于wordpress主题制作的具体实现步骤_php技巧
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址