如何为列表中的每个项添加特殊ID

时间:2014-07-01 15:56:34

标签: php html wordpress wordpress-plugin wp-list-categories

您好我的wordpress网站上有一个基于此plugin的侧边栏。

我希望类别列表中的每个项目都有自己的HTML标识。 如果有多个列表,则该项目的编号不会重复。

例如:

第一个清单:

  • ID = “ITEM_1”
  • ID = “ITEM_2”

第二个清单:

  • ID = “ITEM_3”
  • ID = “ITEM_4”
像这样......

  

知道插件没有为项目ID

代码:

插件的代码在这里:

<?php /*   Plugin Name: List category posts   Plugin URI: https://github.com/picandocodigo/List-Category-Posts   Description: List Category Posts allows you to list posts from a category into a post/page using the [catlist] shortcode. This shortcode accepts a category name or id, the order in which you want the posts to display, and the number of posts to display. You can use [catlist] as many times as needed with different arguments. Usage: [catlist argument1=value1 argument2=value2].   Version: 0.49.1   Author: Fernando Briano   Author URI: http://picandocodigo.net/

  Text Domain:   list-category-posts   Domain Path:   /languages/

  Copyright 2008-2014  Fernando Briano  (email : fernando@picandocodigo.net)

  This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by   the Free Software Foundation; either version 3 of the License, or   any later version.

  This program is distributed in the hope that it will be useful,   but WITHOUT ANY WARRANTY; without even the implied warranty of   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   GNU General Public License for more details.

  You should have received a copy of the GNU General Public License   along with this program; if not, write to the Free Software   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

load_plugin_textdomain( 'list-category-posts', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );

include 'include/ListCategoryPostsWidget.php'; include 'include/options.php'; require_once 'include/CatListDisplayer.php';

class ListCategoryPosts{   /**    * Gets the shortcode parameters and instantiate plugin objects    * @param $atts    * @param $content   
*/   static function catlist_func($atts, $content = null) {
    $atts = shortcode_atts(array(
                             'id' => '0',
                             'name' => '',
                             'orderby' => 'date',
                             'order' => 'desc',
                             'numberposts' => '',
                             'date' => 'no',
                             'date_tag' => '',
                             'date_class' =>'',
                             'dateformat' => get_option('date_format'),
                             'date_modified' => '',
                             'date_modified_tag' => '',
                             'date_modified_class' => '',
                             'author' => 'no',
                             'author_posts_link' => 'no',
                             'author_tag' =>'',
                             'author_class' => '',
                             'author_posts' => '',
                             'template' => 'default',
                             'excerpt' => 'no',
                             'excerpt_size' => '55',
                             'excerpt_strip' => 'yes',
                             'excerpt_overwrite' => 'no',
                             'excerpt_tag' =>'',
                             'excerpt_class' =>'',
                             'exclude' => '0',
                             'excludeposts' => '0',
                             'offset' => '0',
                             'tags' => '',
                             'exclude_tags' => '',
                             'currenttags' => '',
                             'content' => 'no',
                             'content_tag' => '',
                             'content_class' => '',
                             'display_id' => 'no',
                             'catlink' => 'no',
                             'catname' => 'no',
                             'catlink_string' => '',
                             'catlink_tag' =>'',
                             'catlink_class' => '',
                             'comments' => 'no',
                             'comments_tag' => '',
                             'comments_class' => '',
                             'starting_with' => '',
                             'thumbnail' => 'no',
                             'thumbnail_size' => 'thumbnail',
                             'thumbnail_class' => '',
                             'title_tag' => '',
                             'title_class' => '',
                             'title_limit' => '0',
                             'post_type' => '',
                             'post_status' => '',
                             'post_parent' => '0',
                             'post_suffix' => '',
                             'show_protected' => 'no',
                             'class' => 'lcp_catlist',
                             'customfield_name' => '',
                             'customfield_value' =>'',
                             'customfield_display' =>'',
                             'customfield_display_name' =>'',
                             'customfield_orderby' =>'',
                             'customfield_tag' => '',
                             'customfield_class' => '',
                             'taxonomy' => '',
                             'categorypage' => '',
                             'category_count' => '',
                             'morelink' => '',
                             'morelink_class' => '',
                             'morelink_tag' => '',
                             'posts_morelink' => '',
                             'posts_morelink_class' => '',
                             'year' => '',
                             'monthnum' => '',
                             'search' => '',
                             'link_target' => '',
                             'pagination' => 'no',
                             'pagination_next' => '>>',
                             'pagination_prev' => '<<',
                             'no_posts_text' => "",
                             'instance' => '0'
                           ), $atts);
    if( $atts['numberposts'] == ''){
      $atts['numberposts'] = get_option('numberposts');
    }
    if( $atts['pagination'] == 'yes'){
      lcp_pagination_css();
    }
    $catlist_displayer = new CatListDisplayer($atts);
    return $catlist_displayer->display();   } }

add_shortcode( 'catlist', array('ListCategoryPosts', 'catlist_func') );

function lpc_meta($links, $file) {   $plugin = plugin_basename(__FILE__);

  if ($file == $plugin):
    return array_merge(
      $links,
      array( sprintf('<a href="http://wordpress.org/extend/plugins/list-category-posts/other_notes/">%s</a>',
__('How to use','list-category-posts')) ),
      array( sprintf('<a href="http://picandocodigo.net/programacion/wordpress/list-category-posts-wordpress-plugin-english/#support">%s</a>',
__('Donate','list-category-posts')) ),
      array( sprintf('<a href="https://github.com/picandocodigo/List-Category-Posts">%s</a>',
__('Fork on Github','list-category-posts')) )
    );   endif;

  return $links; }

add_filter( 'plugin_row_meta', 'lpc_meta', 10, 2 );

function lcp_pagination_css(){   if ( @file_exists( get_stylesheet_directory() . '/lcp_paginator.css' ) ):
    $css_file = get_stylesheet_directory_uri() . '/lcp_paginator.css';   elseif ( @file_exists( get_template_directory() . '/lcp_paginator.css' ) ):
    $css_file = get_template_directory_uri() . '/lcp_paginator.css';   else:
    $css_file = WP_PLUGIN_URL . '/' . basename( __DIR__ ) . '/lcp_paginator.css';   endif;

  wp_enqueue_style( 'lcp_paginator', $css_file); }

/**  * TO-DO:
- Pagination * DONE - Need to add "page" text
- Add Older Posts at bottom of List Category Post page
- Simpler template system
- Exclude child categories  */

1 个答案:

答案 0 :(得分:0)

样式表上的#用于ID。如果您使用#mystyle {}(或其他)创建样式并将其指定给项目,那么将为您提供所需的结果。