以下內容属于 ‘WordPress’ 分类:
百度了一堆都不太好用,主要是我要在自定义文章类型(custom_type)的文章中调用默认文章类型(post)的第一张图片。其实我是为了扩充版面,让内容看起来不至于空虚,所以调用任意一张都可以。 Google了一下,找到了,这里记录一下。 123456789101112function get_first_image( $post_id ) { $attach = get_children( array( 'post_parent' => $post_id, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'DESC', 'numberposts' => […]
(more...)
特别是做资源站,有提取码之类的字段 还是挺管用。分享给大家。 复制文本框中的文字 HTML代码部分 1234<div> <input type="text" value="The Text to Copy" id="copyMe"> <button onclick="copyMyText()">复制到剪贴板</button> </div> JavaScript 部分 12345678910<script> function copyMyText() { //select the element with the id "copyMe", must be a text box var textToCopy = document.getElementById("copyMe"); //select the text in the text box […]
(more...)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566//去除分类标志代码 add_action( 'load-themes.php', 'no_category_base_refresh_rules'); add_action('created_category', 'no_category_base_refresh_rules'); add_action('edited_category', 'no_category_base_refresh_rules'); add_action('delete_category', 'no_category_base_refresh_rules'); function no_category_base_refresh_rules() { global $wp_rewrite; $wp_rewrite -> flush_rules(); } // register_deactivation_hook(__FILE__, 'no_category_base_deactivate'); // function no_category_base_deactivate() { // remove_filter('category_rewrite_rules', 'no_category_base_rewrite_rules'); // // We don't want to insert our custom rules again // no_category_base_refresh_rules(); // } // Remove category base add_action('init', 'no_category_base_permastruct'); function […]
(more...)
默认我们都知道WordPress的附件目录是[域名]/wp-content/uploads/[年份月],如果我们需要改变成下面这种形式: [域名]/uploads/[年份月] 那么我们需要打开网站根目录的wp-config.php文件,在末尾增进一行代码 1define('UPLOADS','uploads'); 如果需要改成下面这种形式。 [域名]/pic/[年份月] 那么代码就是这样: 1define('UPLOADS','pic'); 当然你还可以自定义其他的目录名称,是不是很简单,那你也可以去试试。
(more...)
WordPress显示有文章的月份归档代码。 1wp_get_archives('type=monthly');
(more...)
WordPress DX-watermark 搬家无法预览的一个问题,是由于路径变化,之前是home/wwwroot/…… ,搬家后变成了mnt/wwwroot/…… ,导致无法预览。 进入phpMyAdmin=>选定博客对应数据库=>搜索=>如图输入dx-watermark-options,全选并执行。 发现在wp-options表里有数据,点击后面的浏览。 然后编辑所有结果中的option_value栏位(应该只有2行),然后将相应路径全部更正为现用的主机的绝对路径。 参考:https://zhang.ge/1298.html
(more...)
这里以自定义文章类型“shuoshuo”为例,涉及插件/baidu-sitemap-generator/baidu_sitemap.php的两处修改,174行和314行,废话不多说,直接贴代码。(举例为”baidu-sitemap-generator v1.6.5) 找到插件的baidu_sitemap.php文件,打开。 找到174行代码 1AND (post_type='post' or post_type='page') 改为: 1AND (post_type='post' or post_type='page' or post_type='shuoshuo') 找到314行代码 1AND post_type='post' 改为: 1AND (post_type='post' or post_type='shuoshuo') 来源:https://www.mrwu.red/biji/801.html
(more...)
1234567891011121314151617181920212223242526272829303132333435/* Register Custom Post Type */ add_action( 'init', 'create_products_post_type' ); // add portfolio function create_products_post_type() { $labels = array( 'name' => __('产品', 'WPGP'), 'singular_name' => __('产品', 'WPGP'), 'add_new' […]
(more...)
以自定义域的名称为spydance为例 1234567$spydance = get_post_meta($pid, 'spydance', true); <?php if(isset($spydance ) && $spydance != "") : ?> 有值需要显示的内容 <?php else : ?> //有值显示 没有值需要显示的内容//没有值显示 <?php endif; ?>
(more...)
如果是栏目的值是数字的话,比较好用。参考下面代码 mycpt是注册的自定义文章格式,比如你注册的product或者movie就对应修改下。 Modifying the Custom Columns for a Post Type 1234567891011121314add_filter( 'manage_mycpt_posts_columns', 'set_custom_edit_mycpt_columns' ); function set_custom_edit_mycpt_columns( $columns ) { $date = $colunns['date']; unset( $columns['date'] ); $columns['photo'] = __( 'Photo', 'my-text-domain' ); $columns['custom_taxonomy'] = __( 'Custom Taxonomy', 'my-text-domain' ); $columns['acf_field'] = __( 'ACF Field', 'my-text-domain' ); $columns['date'] = $date; […]
(more...)