Below, you’ll find a detailed guide on how to add the Zotpress Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Zotpress Plugin shortcodes not to show or not to work correctly.
Before starting, here is an overview of the Zotpress Plugin and the shortcodes it provides:
"Zotpress is a comprehensive tool designed for WordPress, allowing seamless integration with your Zotero library. Perfect for scholars, it simplifies citation management and academic blogging."
- [zotpress]
- [zotpressInText]
- [zotpressInTextBib]
- [zotpressLib]
Zotpress [zotpress] Shortcode
The Zotpress shortcode is designed to integrate Zotero, a free and open-source reference management software, into WordPress. This shortcode allows users to display a list of their Zotero citations on their WordPress site. The list can be customized based on various parameters such as author, year, item type, collection, tag, and style. The shortcode also supports features like showing images, tags, notes, abstracts, and download links for each citation.
Shortcode: [zotpress]
Parameters
Here is a list of all possible zotpress shortcode parameters and attributes:
user_id
– Identifier for the user’s accountnickname
– Nickname associated with the user’s accountauthor
– Filter the results by author’s nameyear
– Filter the results by publication yearitemtype
– Filter the results by item typecollection_id
– Identifier for a collection to displayitem_key
– Identifier for a specific item to displaytag_name
– Filter the results by tag namestyle
– Specifies the citation stylelimit
– Limit the number of results displayedsortby
– Sort the results by a specific fieldorder
– Order the results in ascending or descending ordertitle
– Show the title of the itemsimage
– Show the image of the itemsshowtags
– Show the tags associated with the itemsdownloadable
– Show a download link for the itemsshownotes
– Show the notes associated with the itemsabstract
– Show the abstract of the itemscite
– Show a citation link for the itemsmetadata
– Show the metadata of the itemstarget
– Set the target attribute for the item’s linkurlwrap
– Wrap the URL around the title or imagehighlight
– Highlight specific text in the itemsforcenumber
– Force numbering in the list of items
Examples and Usage
Basic example – Displaying a bibliography list with items from a specific collection.
[zotpress collection_id='ABC123' /]
Advanced examples
Displaying a bibliography list with items from a specific collection and author, sorted by year in descending order, and limited to 5 items.
[zotpress collection_id='ABC123' author='John Doe' sortby='year' order='desc' limit='5' /]
Displaying a bibliography list with items from a specific collection and author, sorted by year in descending order, with images, tags, download links, and notes shown.
[zotpress collection_id='ABC123' author='John Doe' sortby='year' order='desc' showimage='yes' showtags='yes' downloadable='yes' shownotes='yes' /]
Displaying a bibliography list with items from a specific collection, filtered by a specific item type (e.g., book), and with a specific citation style applied.
[zotpress collection_id='ABC123' itemtype='book' style='apa' /]
PHP Function Code
In case you have difficulties debugging what causing issues with [zotpress]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'zotpress', 'Zotpress_func' );
Shortcode PHP function:
function Zotpress_func( $atts )
{
extract( shortcode_atts( array(
'user_id' => false, // deprecated
'userid' => false,
'nickname' => false,
'nick' => false,
'author' => false,
'authors' => false,
'year' => false,
'years' => false,
'itemtype' => false, // for selecting by itemtype; assumes one type
'item_type' => 'items',
'data_type' => false, // deprecated
'datatype' => 'items',
'collection_id' => false,
'collection' => false,
'collections' => false,
'item_key' => false,
'item' => false,
'items' => false,
'inclusive' => 'yes',
'tag_name' => false,
'tag' => false,
'tags' => false,
'style' => false,
'limit' => false,
'sortby' => 'default',
'order' => false,
'sort' => false,
'title' => 'no',
'image' => false,
'images' => false,
'showimage' => 'no',
'showtags' => 'no',
'downloadable' => 'no',
'download' => 'no',
'shownotes' => false,
'note' => false,
'notes' => 'no',
'abstract' => false,
'abstracts' => 'no',
'cite' => 'no',
'citeable' => false,
'metadata' => false,
'target' => false,
'urlwrap' => false,
'highlight' => false,
'forcenumber' => false,
'forcenumbers' => false
), $atts, 'zotpress'));
// +---------------------------+
// | FORMAT & CLEAN PARAMETERS |
// +---------------------------+
// Filter by account
if ($user_id) {
$api_user_id = zp_clean_param( $user_id );
} elseif ($userid) {
$api_user_id = zp_clean_param( $userid );
} else $api_user_id = false;
if ($nickname) $nickname = zp_clean_param( $nickname );
if ($nick) $nickname = zp_clean_param( $nick );
// Filter by author
$author = zp_clean_param( $author );
if ($authors) $author = zp_clean_param( $authors );
// Filter by year
if ($year) {
$year = zp_clean_param( $year );
} elseif ($years) {
$year = zp_clean_param( $years );
} elseif (strpos($year, ",") > 0) {
$year = explode(",", $year);
} else $year = "";
// Filter by itemtype
// TODO: Allow for multiple itemtypes in one shortcode?
$itemtype = zp_clean_param( $itemtype );
if ( $itemtype !== false )
{
// Make sure it's one of the accepted types
$officialItemTypes = array(
'book',
'bookSection',
'journalArticle',
'conferencePaper',
'thesis',
'report',
'encyclopediaArticle',
'newspaperArticle',
'magazineArticle',
'presentation',
'interview',
'dictionaryEntry',
'document',
'manuscript',
'patent',
'map',
'blogPost',
'webpage',
'artwork',
'film',
'audioRecording',
'statute',
'bill',
'case',
'hearing',
'forumPost',
'letter',
'email',
'instantMessage',
'software',
'podcast',
'radioBroadcast',
'tvBroadcast',
'videoRecording',
'attachment',
'note',
'preprint'
);
$itemtypeCheck = false;
foreach ($officialItemTypes as $type)
if ( $itemtype == $type ) $itemtypeCheck = true;
if ( !$itemtypeCheck )
$itemtype = false; // Default is no itemtype filter
}
// Format with datatype and content
if ($item_type) {
$item_type = zp_clean_param( $item_type );
} elseif ($data_type) {
$item_type = zp_clean_param( $data_type );
} else $item_type = zp_clean_param( $datatype );
// Filter by collection
$collection_id = false;
if ($collection_id) {
$collection_id = zp_clean_param( $collection_id );
} elseif ($collection) {
$collection_id = zp_clean_param( $collection );
} elseif ($collections) {
$collection_id = zp_clean_param( $collections );
}
$collection_id = str_replace(" ", "", $collection_id );
if (strpos($collection_id, ",") > 0) $collection_id = explode(",", $collection_id);
if ($item_type == "collections" && isset($_GET['zpcollection']) ) $collection_id = htmlentities( urldecode( $_GET['zpcollection'] ) );
// Filter by tag
$tag_id = false;
if ($tag_name) {
$tag_id = zp_clean_param( $tag_name );
} elseif ($tags) {
$tag_id = zp_clean_param( $tags );
} else $tag_id = zp_clean_param( $tag );
$tag_id = str_replace("+", "", $tag_id);
if (strpos($tag_id, ",") > 0) $tag_id = explode(",", $tag_id);
if ($item_type == "tags" && isset($_GET['zptag']) ) $tag_id = htmlentities( urldecode( $_GET['zptag'] ) );
// Filter by itemkey
if ($item_key) $item_key = zp_clean_param( $item_key );
if ($items) $item_key = zp_clean_param( $items );
if ($item) $item_key = zp_clean_param( $item );
if (strpos($item_key, ", ") > 0) $item_key = str_replace(', ',',',html_entity_decode($item_key)); // remove spces after commas
// if (strpos($item_key, ",") > 0) $item_key = explode(",", $item_key); // ? break at commas?
$item_key = str_replace(" ", "", $item_key ); // remove any spaces
// Inclusive (for multiple authors)
$inclusive = $inclusive == "yes" || $inclusive == "true" || $inclusive === true;
// Format style
$style = zp_clean_param( $style );
// Limit
$limit = (int) zp_clean_param( $limit );
// Order / sort
$sortby = zp_clean_param( $sortby );
if ($order) {
$order = strtolower(zp_clean_param( $order ));
} elseif ($sort) {
$order = strtolower(zp_clean_param( $sort ));
}
if ($order === false) $order = "asc";
// Show title
// Sorting by secondary sort
$title = zp_clean_param( $title );
if ($title == "yes" || $title == "true" || $title === true) {
$title = "year";
} elseif ($title == "no" || $title == "false") {
$title = false;
}
// Show image
if ($showimage) $showimage = zp_clean_param( $showimage );
if ($image) $showimage = zp_clean_param( $image );
if ($images) $showimage = zp_clean_param( $images );
if ($showimage == "yes" || $showimage == "true" || $showimage === true) {
$showimage = true;
} elseif ($showimage === "openlib") {
$showimage = "openlib";
} else $showimage = false;
// Show tags
$showtags = $showtags == "yes" || $showtags == "true" || $showtags === true;
// Show download link
if ($download == "yes" || $download == "true" || $download === true
|| $downloadable == "yes" || $downloadable == "true" || $downloadable === true)
$downloadable = true; else $downloadable = false;
// Show notes
if ($shownotes) {
$shownotes = zp_clean_param( $shownotes );
} elseif ($notes) {
$shownotes = zp_clean_param( $notes );
} elseif ($note) {
$shownotes = zp_clean_param( $note );
}
$shownotes = $notes == "yes" || $notes == "true" || $notes === true;
// Show abstracts
if ($abstracts) $abstracts = zp_clean_param( $abstracts );
if ($abstract) $abstracts = zp_clean_param( $abstract );
$abstracts = $abstracts == "yes" || $abstracts == "true" || $abstracts === true;
// Show cite link
if ($cite) $citeable = zp_clean_param( $cite );
if ($citeable) $citeable = zp_clean_param( $citeable );
$citeable = $citeable == "yes" || $citeable == "true" || $citeable === true;
if ( ! preg_match("/^[0-9a-zA-Z]+$/", $metadata) ) $metadata = false;
// URL attributes
if ($target == "yes" || $target == "_blank" || $target == "new" || $target == "true" || $target === true)
$target = true; else $target = false;
$urlwrap = $urlwrap == "title" || $urlwrap == "image" ? zp_clean_param( $urlwrap ) : false;
$highlight = $highlight ? zp_clean_param( $highlight ) : false;
if ( $forcenumber == "yes" || $forcenumber == "true" || $forcenumber === true
|| $forcenumbers == "yes" || $forcenumbers == "true" || $forcenumbers === true )
$forcenumber = true; else $forcenumber = false;
// +-------------+
// | GET ACCOUNT |
// +-------------+
global $wpdb;
global $post;
// Turn on/off minified versions if testing/live
$minify = ''; if ( ZOTPRESS_LIVEMODE ) $minify = '.min';
wp_enqueue_script( 'zotpress.shortcode.bib'.$minify.'.js' );
// Get account (api_user_id)
$zp_account = false;
if ($nickname !== false) {
$zp_account = $wpdb->get_row("SELECT * FROM ".$wpdb->prefix."zotpress WHERE nickname='".$nickname."'", OBJECT);
if ( is_null($zp_account) ):
return "<p>Sorry, but the selected Zotpress nickname can't be found.</p>";
endif;
$api_user_id = $zp_account->api_user_id;
} elseif ($api_user_id !== false) {
$zp_account = $wpdb->get_row("SELECT * FROM ".$wpdb->prefix."zotpress WHERE api_user_id='".$api_user_id."'", OBJECT);
if ( is_null($zp_account) ):
return "<p>Sorry, but the selected Zotpress account can't be found.</p>";
endif;
$api_user_id = $zp_account->api_user_id;
} elseif ($api_user_id === false && $nickname === false) {
if (get_option("Zotpress_DefaultAccount") !== false)
{
$api_user_id = get_option("Zotpress_DefaultAccount");
$zp_account = $wpdb->get_row("SELECT * FROM ".$wpdb->prefix."zotpress WHERE api_user_id ='".$api_user_id."'", OBJECT);
}
else // When all else fails ...
{
$zp_account = $wpdb->get_row("SELECT * FROM ".$wpdb->prefix."zotpress LIMIT 1", OBJECT);
$api_user_id = $zp_account->api_user_id;
}
}
// Generate instance id for shortcode
$temp_item_key = is_array( $item_key ) ? implode( "-", $item_key) : $item_key;
$temp_collection_id = is_array( $collection_id ) ? implode( "-", $collection_id) : $collection_id;
$temp_tag_name = is_array( $tag_id ) ? implode( "-", $tag_id) : $tag_id;
$temp_author = is_array( $author ) ? implode( "-", $author) : $author;
$temp_year = is_array( $year ) ? implode( "-", $year) : $year;
$temp_sortby = is_array( $sortby ) ? implode( "-", $sortby) : $sortby;
// REVIEW: Added post ID
$instance_id = "zotpress-".md5($post->ID.$api_user_id.$nickname.$temp_author.$temp_year.$itemtype.$item_type.$temp_collection_id.$temp_item_key.$temp_tag_name.$style.$temp_sortby.$order.$limit.$showimage.$showtags.$downloadable.$shownotes.$citeable.$inclusive);
// Prepare item key
if ( $item_key && gettype( $item_key ) != "string" ) $item_key = implode( ",", $item_key );
// Prepare collection
if ( $collection_id && gettype( $collection_id ) != "string" ) $collection_id = implode( ",", $collection_id );
// Prepare tags
if ( $tag_id && gettype( $tag_id ) != "string" ) $tag_id = implode( ",", $tag_id );
// Set up request vars
$request_start = 0;
$request_last = 0;
$overwrite_last_request = false;
// Set up Library vars
$is_dropdown = false;
$maxresults = 50;
$maxperpage = 10;
$maxtags = 100;
// Set up Search vars
$term = false;
// Set up Update vars
$update = false;
$zp_output = '<div id="' . $instance_id . '"';
$zp_output .= ' class="zp-Zotpress zp-Zotpress-Bib wp-block-group';
if ( $forcenumber ) $zp_output .= " forcenumber";
$zp_output .= '">
<span class="ZP_API_USER_ID" style="display: none;">'.$api_user_id.'</span>
<span class="ZP_ITEM_KEY" style="display: none;">'.$item_key.'</span>
<span class="ZP_COLLECTION_ID" style="display: none;">'.$collection_id.'</span>
<span class="ZP_TAG_ID" style="display: none;">'.$tag_id.'</span>
<span class="ZP_AUTHOR" style="display: none;">'.$author.'</span>
<span class="ZP_YEAR" style="display: none;">'.$year.'</span>
<span class="ZP_ITEMTYPE" style="display: none;">'.$itemtype.'</span>
<span class="ZP_ITEM_TYPE" style="display: none;">'.$item_type.'</span>
<span class="ZP_INCLUSIVE" style="display: none;">'.$inclusive.'</span>
<span class="ZP_STYLE" style="display: none;">'.$style.'</span>
<span class="ZP_LIMIT" style="display: none;">'.$limit.'</span>
<span class="ZP_SORTBY" style="display: none;">'.$sortby.'</span>
<span class="ZP_ORDER" style="display: none;">'.$order.'</span>
<span class="ZP_TITLE" style="display: none;">'.$title.'</span>
<span class="ZP_SHOWIMAGE" style="display: none;">'.$showimage.'</span>
<span class="ZP_SHOWTAGS" style="display: none;">'.$showtags.'</span>
<span class="ZP_DOWNLOADABLE" style="display: none;">'.$downloadable.'</span>
<span class="ZP_NOTES" style="display: none;">'.$shownotes.'</span>
<span class="ZP_ABSTRACT" style="display: none;">'.$abstracts.'</span>
<span class="ZP_CITEABLE" style="display: none;">'.$citeable.'</span>
<span class="ZP_TARGET" style="display: none;">'.$target.'</span>
<span class="ZP_URLWRAP" style="display: none;">'.$urlwrap.'</span>
<span class="ZP_FORCENUM" style="display: none;">'.$forcenumber.'</span>
<span class="ZP_HIGHLIGHT" style="display: none;">'.$highlight.'</span>
<span class="ZP_POSTID" style="display: none;">'.$post->ID.'</span>
<span class="ZOTPRESS_PLUGIN_URL" style="display:none;">'.ZOTPRESS_PLUGIN_URL.'</span>
<div class="zp-List loading">';
// +--------------------------------+
// | GENERATE SHORTCODE PLACEHOLDER |
// +--------------------------------+
if ( $zp_account === false )
{
$zp_output .= "\n<div id='".$instance_id."' class='zp-Zotpress'>Sorry, no citation(s) found for this account.</div>\n";
}
else // Make the first request via PHP for SEO purposes
{
$_GET['instance_id'] = $instance_id;
$_GET['api_user_id'] = $api_user_id;
$_GET['item_key'] = $item_key;
$_GET['collection_id'] = $collection_id;
$_GET['tag_id'] = $tag_id;
$_GET['author'] = $author;
$_GET['year'] = $year;
$_GET['itemtype'] = $itemtype;
$_GET['item_type'] = $item_type;
$_GET['inclusive'] = $inclusive;
$_GET['style'] = $style;
$_GET['limit'] = $limit;
$_GET['sortby'] = $sortby;
$_GET['order'] = $order;
$_GET['title'] = $title;
$_GET['showimage'] = $showimage;
$_GET['showtags'] = $showtags;
$_GET['downloadable'] = $downloadable;
$_GET['shownotes'] = $shownotes;
$_GET['abstracts'] = $abstracts;
$_GET['citeable'] = $citeable;
$_GET['target'] = $target;
$_GET['urlwrap'] = $urlwrap;
$_GET['forcenumber'] = $forcenumber;
$_GET['highlight'] = $highlight;
$_GET['request_start'] = $request_start;
$_GET['request_last'] = $request_last;
$_GET['is_dropdown'] = $is_dropdown;
$_GET['maxresults'] = $maxresults;
$_GET['maxperpage'] = $maxperpage;
$_GET['maxtags'] = $maxtags;
$_GET['term'] = $term;
$_GET['update'] = $update;
$_GET['overwrite_last_request'] = $overwrite_last_request;
$zp_output .= "\n\t\t\t<div class=\"zp-SEO-Content\">\n";
$zp_output .= Zotpress_shortcode_request( true ); // Check catche first
$zp_output .= "\n\t\t\t</div><!-- .zp-zp-SEO-Content -->\n";
}
// Indicate that shortcode is displayed
$GLOBALS['zp_is_shortcode_displayed'] = true;
return $zp_output . "\t\t</div><!-- .zp-List -->\n\t</div><!--.zp-Zotpress-->\n\n";
}
Code file location:
zotpress/zotpress/zotpress.php
Zotpress [zotpressInText] Shortcode
The Zotpress In-Text shortcode is used to insert specific items from Zotero into a WordPress post or page. It allows customization of the citation format and style. The shortcode accepts various parameters like ‘item’, ‘items’, ‘pages’, ‘format’, ‘brackets’, ‘etal’, ‘separator’, ‘and’, ‘userid’, ‘api_user_id’, ‘nickname’, ‘nick’. These parameters help define the details of the citation. The shortcode function ‘Zotpress_zotpressInText’ extracts these parameters, prepares them, and fetches the relevant Zotero account data. It then formats the in-text items as per the given parameters and Zotero account details.
Shortcode: [zotpressInText]
Parameters
Here is a list of all possible zotpressInText shortcode parameters and attributes:
item
– Specifies a single item to display.items
– Specifies multiple items to display.pages
– Sets the pages where the items are displayed.format
– Defines the format of the displayed items.brackets
– Determines whether brackets are used in the format.etal
– Decides if ‘et al.’ is used for multiple authors.separator
– Sets the separator between multiple items.and
– Chooses the conjunction for multiple authors.userid
– Specifies the user ID for the Zotpress account.api_user_id
– Sets the API User ID for the Zotpress account.nickname
– Specifies the nickname for the Zotpress account.nick
– Another parameter for specifying the Zotpress account nickname.
Examples and Usage
Basic example – Displaying a single item citation using the Zotpress shortcode.
[zotpressInText item="NCXAA92F" /]
Advanced examples
Displaying multiple item citations with specific pages using the Zotpress shortcode.
[zotpressInText items="{NCXAA92F,10-15},{55MKF89B,1578},{3ITTIXHP}" /]
Displaying a single item citation with a custom format using the Zotpress shortcode.
[zotpressInText item="NCXAA92F" format="(%a%, %d%, %p%)" /]
Displaying a single item citation with a specific user ID using the Zotpress shortcode.
[zotpressInText item="NCXAA92F" userid="12345" /]
Displaying a single item citation with a specific nickname using the Zotpress shortcode.
[zotpressInText item="NCXAA92F" nickname="john" /]
Displaying a single item citation with a specific API user ID using the Zotpress shortcode.
[zotpressInText item="NCXAA92F" api_user_id="abc123" /]
Displaying a single item citation with a custom separator using the Zotpress shortcode.
[zotpressInText item="NCXAA92F" separator="semicolon" /]
Displaying a single item citation with a custom conjunction using the Zotpress shortcode.
[zotpressInText item="NCXAA92F" and="and" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [zotpressInText]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'zotpressInText', 'Zotpress_zotpressInText' );
Shortcode PHP function:
function Zotpress_zotpressInText ($atts)
{
/*
* GLOBAL VARIABLES
*
* $GLOBALS['zp_shortcode_instances'] {instantiated in zotpress.php}
*
*/
extract(shortcode_atts(array(
'item' => false,
'items' => false,
'pages' => false,
'format' => "(%a%, %d%, %p%)",
'brackets' => false,
'etal' => false, // default (false), yes, no
'separator' => false, // default (comma), semicolon
'and' => false, // ampersand [default], and, comma, comma-amp, comma-and
'userid' => false,
'api_user_id' => false,
'nickname' => false,
'nick' => false
), $atts));
// PREPARE ATTRIBUTES
if ($items)
$items = zpStripQuotes( str_replace(" ", "", $items ));
elseif ($item)
$items = zpStripQuotes( str_replace(" ", "", $item ));
$pages = zpStripQuotes( $pages );
$format = zpStripQuotes( $format );
$brackets = zpStripQuotes( $brackets );
$etal = zpStripQuotes( $etal );
if ( $etal == "default" ) $etal = false;
$separator = zpStripQuotes( $separator );
if ( $separator == "default" ) $separator = false;
$and = zpStripQuotes( $and );
if ( $and == "default" ) $and = false;
if ( $userid ) $api_user_id = zpStripQuotes( $userid );
if ( $nickname ) $nickname = zpStripQuotes( $nickname );
if ( $nick ) $nickname = zpStripQuotes( $nick );
// GET ACCOUNTS
global $wpdb;
global $post;
// Turn on/off minified versions if testing/live
$minify = ''; if ( ZOTPRESS_LIVEMODE ) $minify = '.min';
wp_enqueue_script( 'zotpress.shortcode.intext'.$minify.'.js' );
$zp_account = false;
if ($nickname !== false) {
$zp_account = $wpdb->get_row("SELECT * FROM ".$wpdb->prefix."zotpress WHERE nickname='".$nickname."'", OBJECT);
if ( $zp_account !== null )
$api_user_id = $zp_account->api_user_id;
} elseif ($api_user_id !== false) {
$zp_account = $wpdb->get_row("SELECT * FROM ".$wpdb->prefix."zotpress WHERE api_user_id='".$api_user_id."'", OBJECT);
if ( $zp_account !== null )
$api_user_id = $zp_account->api_user_id;
} elseif ($api_user_id === false && $nickname === false) {
if ( get_option("Zotpress_DefaultAccount") !== false )
{
$api_user_id = get_option("Zotpress_DefaultAccount");
$zp_account = $wpdb->get_row("SELECT * FROM ".$wpdb->prefix."zotpress WHERE api_user_id ='".$api_user_id."'", OBJECT);
}
else // When all else fails ...
{
$zp_account = $wpdb->get_row("SELECT * FROM ".$wpdb->prefix."zotpress LIMIT 1", OBJECT);
$api_user_id = $zp_account->api_user_id;
}
}
// Format in-text items:
// Handle the possible formats of item/s for in-text
//
// IN-TEXT FORMATS:
// [zotpressInText item="NCXAA92F"]
// [zotpressInText item="{NCXAA92F}"]
// [zotpressInText item="{NCXAA92F,10-15}"]
// [zotpressInText items="{NCXAA92F,10-15},{55MKF89B,1578},{3ITTIXHP}"]
// [zotpressInText items="{000001:NCXAA92F,10-15},{000003:3ITTIXHP}"]
// So no multiples without curlies or non-curlies in multiples
$all_page_instances = array();
$all_page_instances_str = "";
// // Add `ppp` in front of pages, so we can ignore pages later
// $intextitem["items"] = preg_replace( "/((?=[^}
Code file location:
zotpress/zotpress/zotpress.php
Zotpress [zotpressInTextBib] Shortcode
The Zotpress plugin shortcode ‘zotpressInTextBib’ is used to customize the in-text bibliography display. It allows users to specify styling, sort order, and inclusion of images, tags, and abstracts.
Shortcode: [zotpressInTextBib]
Parameters
Here is a list of all possible zotpressInTextBib shortcode parameters and attributes:
style
– Specifies the citation style to be used.sortby
– Determines the attribute to sort the bibliography by.sort
– Specifies the sorting direction, ascending or descending.image
– Decides whether to show images if available.showtags
– Decides whether to show tags for each citation.title
– Allows the display of the citation title.download
– Enables the option to download the citation.notes
– Determines whether to show notes for the citation.abstract
– Decides whether to show the abstract of the citation.cite
– Enables the option to cite the citation.target
– Determines whether links open in a new window.urlwrap
– Decides whether to wrap the URL around the title or image.highlight
– Specifies the color to highlight the citation.forcenumber
– Forces the display of citation numbers.
Examples and Usage
Basic example – Displaying a bibliography in the default style.
[zotpressInTextBib /]
Advanced examples
Displaying a bibliography sorted by author in descending order.
[zotpressInTextBib sortby="author" order="desc" /]
Displaying a bibliography with images, tags, and download links. The bibliography is styled in APA format and sorted by title in ascending order.
[zotpressInTextBib style="apa" sortby="title" showimage="yes" showtags="yes" download="yes" /]
Displaying a bibliography with abstracts and citation links. The bibliography is styled in MLA format and sorted by publication date in ascending order. The URLs are wrapped around the title.
[zotpressInTextBib style="mla" sortby="date" abstracts="yes" citeable="yes" urlwrap="title" /]
Displaying a bibliography with highlighted text. The bibliography is styled in Chicago format and sorted by author in ascending order. The highlighted text is “important”.
[zotpressInTextBib style="chicago" sortby="author" highlight="important" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [zotpressInTextBib]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'zotpressInTextBib', 'Zotpress_zotpressInTextBib' );
Shortcode PHP function:
function Zotpress_zotpressInTextBib ($atts)
{
/*
* RELIES ON THESE GLOBAL VARIABLES:
*
* $GLOBALS['zp_shortcode_instances'][$post->ID] {instantiated previously}
*
*/
extract(shortcode_atts(array(
'style' => false,
'sortby' => "default",
'sort' => false,
'order' => false,
'image' => false,
'images' => false,
'showimage' => "no",
'showtags' => "no",
'title' => "no",
'download' => "no",
'downloadable' => false,
'notes' => false,
'abstract' => false,
'abstracts' => false,
'cite' => false,
'citeable' => false,
'target' => false,
'urlwrap' => false,
'highlight' => false,
'forcenumber' => false,
'forcenumbers' => false
), $atts));
global $post;
// FORMAT PARAMETERS
$style = str_replace('"','',html_entity_decode($style));
$sortby = str_replace('"','',html_entity_decode($sortby));
if ($order) {
$order = str_replace('"','',html_entity_decode($order));
} elseif ($sort) {
$order = str_replace('"','',html_entity_decode($sort));
} else $order = "asc";
$order = strtolower($order);
// Show image
if ($showimage) $showimage = str_replace('"','',html_entity_decode($showimage));
if ($image) $showimage = str_replace('"','',html_entity_decode($image));
if ($images) $showimage = str_replace('"','',html_entity_decode($images));
if ($showimage == "yes" || $showimage == "true" || $showimage === true) {
$showimage = true;
} elseif ($showimage === "openlib") {
$showimage = "openlib";
} else $showimage = false;
// Show tags
$showtags = $showtags == "yes" || $showtags == "true" || $showtags === true;
$title = str_replace('"','',html_entity_decode($title));
if ($download) {
$download = str_replace('"','',html_entity_decode($download));
} elseif ($downloadable) {
$download = str_replace('"','',html_entity_decode($downloadable));
}
$download = $download == "yes" || $download == "true" || $download === true;
$shownotes = str_replace('"','',html_entity_decode($notes));
if ($abstracts) {
$abstracts = str_replace('"','',html_entity_decode($abstracts));
} elseif ($abstract) {
$abstracts = str_replace('"','',html_entity_decode($abstract));
}
if ($citeable) {
$citeable = str_replace('"','',html_entity_decode($citeable));
} elseif ($cite) {
$citeable = str_replace('"','',html_entity_decode($cite));
}
if ($target == "new" || $target == "yes" || $target == "_blank" || $target == "true" || $target === true) $target = true;
else $target = false;
$urlwrap = $urlwrap == "title" || $urlwrap == "image" ? str_replace('"','',html_entity_decode($urlwrap)) : false;
$highlight = $highlight ? str_replace('"','',html_entity_decode($highlight)) : false;
if ($forcenumber == "yes" || $forcenumber == "true" || $forcenumber === true)
$forcenumber = true;
if ($forcenumbers == "yes" || $forcenumbers == "true" || $forcenumbers === true)
$forcenumber = true;
// Set up request vars
$request_start = 0;
$request_last = 0;
$overwrite_last_request = false;
$update = false;
// Set up item key
$item_key = "";
// Get in-text items
if ( isset( $GLOBALS['zp_shortcode_instances'][$post->ID] ) )
{
// Handle the possible formats of item/s for in-text
//
// IN-TEXT FORMATS:
// [zotpressInText item="NCXAA92F"]
// [zotpressInText item="{NCXAA92F}"]
// [zotpressInText item="{NCXAA92F,10-15}"]
// [zotpressInText items="{NCXAA92F,10-15},{55MKF89B,1578},{3ITTIXHP}"]
// [zotpressInText items="{000001:NCXAA92F,10-15},{000003:3ITTIXHP}"]
// So no multiples without curlies or non-curlies in multiples
foreach ( $GLOBALS['zp_shortcode_instances'][$post->ID] as $intextitem )
{
// REVIEW: Actually, let's just remove pages
$intextitem["items"] = preg_replace( "/(((,))+([\w\d-]+(})+))++/", "}", $intextitem["items"] );
// Add separator if not the start
if ( $item_key != "" ) $item_key .= ";";
// Add to the item key
$item_key .= $intextitem["items"];
}
Code file location:
zotpress/zotpress/zotpress.php
Zotpress [zotpressLib] Shortcode
The Zotpress plugin shortcode allows users to customize the display of their Zotero library on WordPress sites. It offers multiple parameters to control the content and layout. . It enables users to filter by account, collection, and type of display. Users can set the minimum length of search results, maximum results per page, and maximum tags to display. The shortcode also provides options for citation, downloading, and image display.
Shortcode: [zotpressLib]
Parameters
Here is a list of all possible zotpressLib shortcode parameters and attributes:
user_id
– Deprecated user ID for Zotpress accountuserid
– User ID for Zotpress accountnickname
– Nickname for Zotpress accountnick
– Alternative attribute for nicknametype
– Specifies display type: dropdown, searchbarsearchby
– Search filter: all, collections, items, tagsminlength
– Minimum search characters, default is 3maxresults
– Maximum number of search resultsmaxperpage
– Maximum results per pagemaxtags
– Maximum number of tags for dropdownsortby
– Sort results by: default, title, author, etc.order
– Result order: ascending or descendingcollection_id
– Specifies collection to displaycollection
– Alternative attribute for collection_idcollections
– Currently only supports single collectionstyle
– Specifies citation stylecite
– Enables citation optionciteable
– Alternative attribute for citedownload
– Enables download optiondownloadable
– Alternative attribute for downloadshowimage
– Enables display of item imagesshowimages
– Alternative attribute for showimageshowtags
– Enables display of tags, not implemented yetabstract
– Show abstract, not implemented yetnotes
– Show notes, not implemented yetforcenumber
– Forcibly number items, not implemented yettoplevel
– Specifies top level of displaytarget
– Specifies link target: new tab or same taburlwrap
– Wraps URL around the titlebrowsebar
– Enables the browse bar, default is true
Examples and Usage
Basic example – Display a dropdown menu with a minimum of 3 characters for search and maximum results of 50.
[zotpressLib type="dropdown" minlength=3 maxresults=50 /]
Advanced examples
Display a search bar that filters by collections and tags, with a minimum of 5 characters for search, maximum results of 100, and maximum of 10 results per page. The results are sorted by title in ascending order.
[zotpressLib type="searchbar" searchby="collections,tags" minlength=5 maxresults=100 maxperpage=10 sortby="title" order="asc" /]
Display a dropdown menu for a specific user with nickname ‘john’, that filters by items, with a minimum of 3 characters for search, maximum results of 50, and maximum of 10 tags. The results are sorted by date in descending order, and the images and tags are also displayed.
[zotpressLib nickname="john" type="dropdown" searchby="items" minlength=3 maxresults=50 maxtags=10 sortby="date" order="desc" showimages=true showtags=true /]
PHP Function Code
In case you have difficulties debugging what causing issues with [zotpressLib]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'zotpressLib', 'Zotpress_zotpressLib' );
Shortcode PHP function:
function Zotpress_zotpressLib( $atts )
{
extract( shortcode_atts( array(
'user_id' => false, // deprecated
'userid' => false,
'nickname' => false,
'nick' => false,
'type' => false, // dropdown, searchbar
'searchby' => false, // searchbar only - all [default], collections, items, tags
'minlength' => 3, // searchbar only - 3 [default]
'maxresults' => 50,
'maxperpage' => 10,
'maxtags' => 100, // dropdown only
'sortby' => 'default',
'order' => 'asc',
'collection_id' => false,
'collection' => false,
'collections' => false, // only single for now, though
'style' => false,
'cite' => false,
'citeable' => false,
'download' => false,
'downloadable' => false,
'showimage' => false,
'showimages' => false,
'showtags' => false, // not implemented
'abstract' => false, // not implemented
'notes' => false, // not implemented
'forcenumber' => false, // not implemented
'toplevel' => 'toplevel',
'target' => false,
'urlwrap' => false,
'browsebar' => true // added 7.3.1
), $atts, "zotpress"));
// FORMAT PARAMETERS
// Filter by account
if ($user_id) {
$api_user_id = str_replace('"','',html_entity_decode($user_id));
} elseif ($userid) {
$api_user_id = str_replace('"','',html_entity_decode($userid));
} else $api_user_id = false;
if ($nickname) $nickname = str_replace('"','',html_entity_decode($nickname));
if ($nick) $nickname = str_replace('"','',html_entity_decode($nick));
// Type of display
$type = $type ? str_replace('"','',html_entity_decode($type)) : "dropdown";
// Filter by collection
if ($collection_id) {
$collection_id = zp_clean_param( $collection_id );
} elseif ($collection) {
$collection_id = zp_clean_param( $collection );
} elseif ($collections) {
$collection_id = zp_clean_param( $collections );
} elseif (isset($_GET['collection_id'])
&& preg_match("/^[a-zA-Z0-9]+$/", $_GET['collection_id'])) {
$collection_id = zp_clean_param( $_GET['collection_id'] );
} elseif (isset($_GET['subcollection_id'])
&& preg_match("/^[a-zA-Z0-9]+$/", $_GET['subcollection_id'])) {
$collection_id = zp_clean_param( $_GET['subcollection_id'] );
}
// Filters
if ( $searchby ) $searchby = str_replace('"','',html_entity_decode($searchby));
// Style
if ( $style ) $style = str_replace('"','',html_entity_decode($style));
// Min length
if ( $minlength ) $minlength = str_replace('"','',html_entity_decode($minlength));
// Max results
if ( $maxresults ) $maxresults = str_replace('"','',html_entity_decode($maxresults));
// Max per page
if ( $maxperpage ) $maxperpage = str_replace('"','',html_entity_decode($maxperpage));
// Max tags
if ( $maxtags ) $maxtags = str_replace('"','',html_entity_decode($maxtags));
// Sortby
if ( $sortby ) $sortby = str_replace('"','',html_entity_decode($sortby));
// Order
if ( $order ) $order = str_replace('"','',html_entity_decode($order));
// Citeable
if ( $cite ) $cite = str_replace('"','',html_entity_decode($cite));
if ( $citeable ) $cite = str_replace('"','',html_entity_decode($citeable));
// Downloadable
if ( $download ) $download = str_replace('"','',html_entity_decode($download));
if ( $downloadable ) $download = str_replace('"','',html_entity_decode($downloadable));
// Show tags
if ( $showtags ) $showtags = str_replace('"','',html_entity_decode($showtags));
if ( strpos( $searchby, "tags" ) !== false ) $showtags = true;
// Show image
if ( $showimages ) $showimage = str_replace('"','',html_entity_decode($showimages));
if ( $showimage ) $showimage = str_replace('"','',html_entity_decode($showimage));
if ( $urlwrap ) $urlwrap = str_replace('"','',html_entity_decode($urlwrap));
if ( $toplevel ) $toplevel = str_replace('"','',html_entity_decode($toplevel));
$target = $target && $target != "no";
if ( $browsebar ) $browsebar = str_replace('"','',html_entity_decode($browsebar));
// Get API User ID
global $wpdb;
if ($nickname !== false) {
$zp_account = $wpdb->get_row("SELECT * FROM ".$wpdb->prefix."zotpress WHERE nickname='".$nickname."'", OBJECT);
if ( is_null($zp_account) ): echo "<p>Sorry, but the selected Zotpress nickname can't be found.</p>"; return false; endif;
$api_user_id = $zp_account->api_user_id;
} elseif ($api_user_id !== false) {
$zp_account = $wpdb->get_row("SELECT * FROM ".$wpdb->prefix."zotpress WHERE api_user_id='".$api_user_id."'", OBJECT);
if ( is_null($zp_account) ): echo $api_user_id."<p>Sorry, but the selected Zotpress account can't be found.</p>"; return false; endif;
$api_user_id = $zp_account->api_user_id;
} elseif ($api_user_id === false && $nickname === false) {
if (get_option("Zotpress_DefaultAccount") !== false)
{
$api_user_id = get_option("Zotpress_DefaultAccount");
$zp_account = $wpdb->get_row("SELECT * FROM ".$wpdb->prefix."zotpress WHERE api_user_id ='".$api_user_id."'", OBJECT);
}
else // When all else fails ...
{
$zp_account = $wpdb->get_row("SELECT * FROM ".$wpdb->prefix."zotpress LIMIT 1", OBJECT);
$api_user_id = $zp_account->api_user_id;
}
}
// Use Browse class
$zpLib = new zotpressLib;
$zpLib->setAccount($zp_account);
$zpLib->setType($type);
if ( $searchby ) $zpLib->setFilters($searchby);
$zpLib->setMinLength($minlength);
$zpLib->setMaxResults($maxresults);
$zpLib->setMaxPerPage($maxperpage);
$zpLib->setMaxTags($maxtags);
$zpLib->setStyle($style);
$zpLib->setSortBy($sortby);
$zpLib->setOrder($order);
$zpLib->setCollection($collection_id);
$zpLib->setCiteable($cite);
$zpLib->setDownloadable($download);
$zpLib->setShowTags($showtags);
$zpLib->setShowImage($showimage);
$zpLib->setURLWrap($urlwrap);
$zpLib->setTopLevel($toplevel);
$zpLib->setTarget($target);
$zpLib->setBrowseBar($browsebar);
// Show theme scripts
$GLOBALS['zp_is_shortcode_displayed'] = true;
return $zpLib->getLib();
}
Code file location:
zotpress/zotpress/zotpress.php
Conclusion
Now that you’ve learned how to embed the Zotpress Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.
Leave a Reply