I've output my archive description as per below. However I would like to display the first part before the tag in one place and the rest excluding the first part elsewhere in other tag. Is there a way to split this to output the two different data? It could be split just using the first paragraph instead.
the_archive_description( '<div class="taxonomy-description">', '</div>' );
Try using get_the_archive_description()
instead. This returns the description instead of displaying it, which will allow you to manipulate it however you like using your own code before displaying (or not) parts of it. Kind of like this:
$myDescription = get_the_archive_description();
$sections = explode('<!-- more -->', $myDescription);
echo __( $sections[0], 'default' ); //Put this wherever you want to display the first part
echo __( $sections[1], 'default' ); //Put this wherever you want to display the rest
Related
By default, WordPress ships with a Calendar widget that you can use to display a calendar with the days that have posts. I would like to filter the HTML output of this widget to customize its look. Specifically, the widget displays links to previous and next months at the bottom of the calendar in the following format:
« Jan Feb »
This is the HTML I would like to change.
What I Have Tried
If you look at wp-includes/general-template.php file in WordPress, there is a function called get_calendar() which contains the HTML I wish to change. It also has a filter hook to filter the HTML output at the bottom of the function.
If I use the following code, I can customize the output to remove the « and » and replace them with icons from FontAwesome. This works without issue.
function custom_calendar_output( $calendar_output ) {
$search = array( '«', '»' );
$replace = array( '<i class="far fa-arrow-alt-circle-left"></i>', '<i class="far fa-arrow-alt-circle-right"></i>' );
$cust_calendar_output = str_replace( $search, $replace, $calendar_output );
return $cust_calendar_output;
}
add_filter( 'get_calendar', 'custom_calendar_output' );
What I'm Having Trouble With
I would also like to remove the month text as well as the default arrow. So instead of having it read as: « Jan, It would just display the icon from FontAwesome. The month text changes (e.g. Jan, Feb, Mar) as the user cycles through the past months.
How can I remove both the default arrow and the month text to replace it with a custom icon?
I have read I may need to use preg_replace with regex but I can't seem to get this to work. I have also read that using regex uses a lot of overhead. Is there a cleaner way to do this?
In nodereference field of a content type, Is it possible to show the content type name added with the autocomplete results ?
Example :
I have a content type named Article which has a node reference field (Related content -> field_related_documents), So that this article will referenced to other nodes.
While creating an article, by entering 'help' in 'field_related_documents' I am getting autocomplete results (titles of referenced nodes) like below
helpsystems - rules
Decision management Help
Using help menu
Help support glossary
Instead, I like to show results like below
Page | helpsystems - rules
HelpSystems | Decision management Help
Page | Using help menu
Document | Help support glossary
ie) autocomplete results should display title of other nodes added with their related content type.
How should i achieve this ? Is there any contributed modules available to achieve this?
I created a new custom Module nodereference_patch with below hook
/*
* Altering nodereference/autocomplete menu using menu alter
*/
function nodereference_patch_menu_alter(&$items) {
$items['nodereference/autocomplete']['page callback'] = 'nodereference_patch_new_nodereference_autocomplete';
}
Then, I copied the nodereference_autocomplete function into your custom module, changing it's name to nodereference_patch_new_nodereference_autocomplete.
Then I changed this line:
$matches[$row['title'] ." [nid:$id]"] = '<div class="reference-autocomplete">'. $row['rendered'] . '</div>';
to
$matches[$row['type'] . " | " . $row['title'] . " [nid:$id]"] = '<div class="reference-autocomplete">' . $row['type'] . " | " . $row['rendered'] . '</div>';
I copied _nodereference_potential_references function from nodereference.module to custom module and renamed it as _nodereference_patch_potential_references
Then I changed the following line as
$references = _nodereference_potential_references_standard($field, $string, $match, $ids, $limit);
to
$references = _nodereference_patch_potential_references_standard($field, $string, $match, $ids, $limit);
I copied _nodereference_potential_references_standard from nodereference.module to custom module and renamed it as _nodereference_patch_potential_references_standard
Then I added 'type' element to $references[]. ie) changed following array from
$references[$node->nid] = array(
'title' => $node->node_title,
'rendered' => check_plain($node->node_title),
);
to
$references[$node->nid] = array(
'title' => $node->node_title,
'type' => $node->node_type,
'rendered' => check_plain($node->node_title),
);
I'd be more inclined to use a different approach, using similar methods but rather than copying the full module and renaming this I'd create a new menu_hook and form_alters to update the autocomplete path.
If you're using entity reference rather than node reference you can use views to display the content, not my preferred route but will reduce the amount of custom code. Quick google of a demonstration of this gives the following video (http://codekarate.com/daily-dose-of-drupal/using-views-entity-reference-module-drupal-7)
Also, just a note, if you plan to copy the module out like the above answer I would strongly advise to remove some of the lines from the module info file. The information below '; Information added by drupal.org packaging script on' in the info file is used by the update module and increases the risk of this new module being replaced by the original module.
In my functions file I have this:
function caption_shortcode( $atts, $content = null ) {
return '<span class="caption">' . $content . '</span>';
}
add_shortcode( 'caption', 'caption_shortcode' );
In the CMS page editor I have this:
[caption]My Caption[/caption]
This page is utilizing a custom template file template-mypage.php. My question is: I would like to create multiple short codes types within the CMS such as:
[caption1]My Caption[/caption1]
[caption2]My Caption[/caption2]
[caption3]My Caption[/caption3]
then in my template-mypage.php... I would like to selectively choose where to place [caption1], [caption2], [caption3]... for example [caption1] will go somewhere on the top... [caption2] in the middle and [caption3] towards the bottom of the template-mypage.php, all seperated by some huge chunks of HTML content. I do not want to write any HTML within the WP CMS... all HTML should be written in the template-mypage.php.
Currently I believe WP limits shortcode output to come out of the_content(); Is it possible to do something like the_content_of_caption1(), the_content_of_caption2(), the_content_of_caption3()?
Thanks please let me know!
this product does this perfectly
http://wordpress.org/plugins/multiple-content-blocks/
So here is the main simplepie code I'm trying to use, and I don't really understand how to initialize the other feeds I have set up. Basically what I'm trying to do is place each of those $feeds into different divs so the first div displays all 3 feeds, and then one div for each after that.
<?php
// Include the SimplePie library
require_once('simplepie.inc');
// Because we're using multiple feeds, let's just set the headers here.
header('Content-type:text/html; charset=utf-8');
// These are the feeds we want to use
$feeds = array(
'SITE ONE URL',
'SITE TWO URL',
'SITE THREE URL');
$feeds2 = array(
'SITE ONE URL');
$feeds3 = array(
'SITE TWO URL');
$feeds4 = array(
'SITE THREE URL');
// This array will hold the items we'll be grabbing.
$first_items = array();
// Let's go through the array, feed by feed, and store the items we want.
foreach ($feeds as $url)
{
// Use the long syntax
$feed = new SimplePie();
$feed->set_feed_url($url);
$feed->init();
// How many items per feed should we try to grab?
$items_per_feed = 3;
// As long as we're not trying to grab more items than the feed has, go through them one by one and add them to the array.
for ($x = 0; $x < $feed->get_item_quantity($items_per_feed); $x++)
{
$first_items[] = $feed->get_item($x);
}
// We're done with this feed, so let's release some memory.
unset($feed);
}
// We need to sort the items by date with a user-defined sorting function. Since usort() won't accept "SimplePie::sort_items", we need to wrap it in a new function.
function sort_items($a, $b)
{
return SimplePie::sort_items($a, $b);
}
// Now we can sort $first_items with our custom sorting function.
usort($first_items, "sort_items");
// Begin the (X)HTML page.
?>
I would like to help but need to understand better what you are trying to do. As per my understanding you want to populate a top div with ALL THE CONTENTS OF THE THREE FEEDS and, then, below, have a separate div with each of the feeds contents. Like:
<div id='feeds'>
feed1-content-1
feed1-content-2
feed1-content-3
feed2-content-1
feed2-content-2
feed2-content-3
feed3-content-1
feed3-content-2
feed3-content-3
</div>
<div id='feeds2'>
feed1-content-1
feed1-content-2
feed1-content-3
</div>
<div id='feeds3'>
feed2-content-1
feed2-content-2
feed2-content-3
</div>
<div id='feeds4'>
feed3-content-1
feed3-content-2
feed3-content-3
</div>
If that is what you want, I would like to throw in my 2cents: why the redundancy? However, only the coder really knows what (s)he wants to achieve. My suggestion is simple: just append a paragraph into the divs:
$('#feeds').append('<p>'+feed+'</p>');
and the appropriate feed into the appropriate div in the same way.
Does anyone know of a way to add an input field (or any type of html for the matter) directly above (or below) the title input field on the post edit page ?
I'm looking of a way to do this without modifying core files (I'm doing this as part of a plug-in which creates a custom post-type).
I'm not aware of any available wp hooks in that area of the edit-form-advanced.php file which could help out. I really hope some has come up with a genius workaround !
Since version 3.5 wordpress introduced new hooks for the add/edit post screen called edit_form_after_title and edit_form_after_editor. So now i think we can easily add new html element after wordpress input title and input content.
just use filter like this on your functions.php
add_action( 'edit_form_after_title', 'my_new_elem_after_title' );
function my_new_elem_after_title() {
echo '<h2>Your new element after title</h2>';
}
add_action( 'edit_form_after_editor', 'my_new_elem_after_editor' );
function my_new_elem_after_editor() {
echo '<h2>Your new element after content</h2>';
}
You're on the right track; pursue the add_action('admin_head') point of entry. What you want can specifically be done with a bit of JavaScript + jQuery (which is built into WP). To display the input field above the title input field, do something like this:
add_action('admin_head', 'my_admin_head_in_posts');
function my_admin_head_in_posts() {
?>
jQuery('#post').before(
'<div id="id_my_field" class="updated below-h2">' +
'<input type="text" name="my_field" value="lol" />' +
'</div>'
);
<?php
}
And you should be seeing something like this: