confusing functionality – excerpts and categories/archives
-
I am finding it impossible to tell the difference between using categories/archives and using excerpts, as they seem to do the same thing – both adding buttons to the excerpts. This is also the case with the home page (when it’s not a static page). What i would have expected is that excerpts and categories/archives would operate independently, with excerpts adding buttons to individual excerpts and categories/archives adding one set up buttons for the whole page.
Right now excerpts doesn’t even seem to work unless categories/archives is also enabled. So i think there is definitely some confusion here in what functionality to expect for the applicable page-type settings.
The following changes fixed this problem for me. (Note that WordPress replaces single quotes with curly quotes, so you have to fix those.)
In the file inc/ssba_buttons.php …
1. add filters to insert content at start and end of archive/category pages :
// added @ v6.3.4 to separate excerpts/archives functionality
add_filter (‘loop_start’, ‘ssba_show_buttons_for_archives_before’);
add_filter (‘loop_end’, ‘ssba_show_buttons_for_archives_after’);// added @ v6.3.4 to separate excerpts/archives functionality
function ssba_show_buttons_for_archives_before() {if (is_front_page() && !is_home()) return;
// get sbba settings
$arrSettings = get_ssba_settings();if ($arrSettings[‘ssba_before_or_after’] == ‘before’ || $arrSettings[‘ssba_before_or_after’] == ‘both’) {
ssba_add_buttons_for_archives();
}}
// added @ v6.3.4 to separate excerpts/archives functionality
function ssba_show_buttons_for_archives_after() {if (is_front_page() && !is_home()) return;
// get sbba settings
$arrSettings = get_ssba_settings();if ($arrSettings[‘ssba_before_or_after’] == ‘after’ || $arrSettings[‘ssba_before_or_after’] == ‘both’) {
ssba_add_buttons_for_archives();
}}
2. and a separate function to insert buttons for category/archive pages :
// added @ v6.3.4 to separate excerpts/archives functionality
function ssba_add_buttons_for_archives() {// globals
global $post;// variables
$htmlContent = ”;// get sbba settings
$arrSettings = get_ssba_settings();if (isset($arrSettings[‘ssba_cats_archs’]) && $arrSettings[‘ssba_cats_archs’] == ‘Y’ && is_category()
|| isset($arrSettings[‘ssba_cats_archs’]) && $arrSettings[‘ssba_cats_archs’] == ‘Y’ && is_archive()
|| isset($arrSettings[‘ssba_homepage’]) && $arrSettings[‘ssba_homepage’] == ‘Y’ && is_front_page())
{$strShareText = $arrSettings[‘ssba_share_text’];
// post id
$intPostID = get_the_ID();// ssba div
$htmlShareButtons = ‘<!– Simple Share Buttons Adder (‘.SSBA_VERSION.’) simplesharebuttons.com –><div class=”ssba ssba-wrap”>’;// center if set so
$htmlShareButtons.= ‘<div style=”text-align:’.$arrSettings[‘ssba_align’].'”>’;// add custom text if set and set to placement above or left
if (($strShareText != ”) && ($arrSettings[‘ssba_text_placement’] == ‘above’ || $arrSettings[‘ssba_text_placement’] == ‘left’)) {// check if user has left share link box checked
if ($arrSettings[‘ssba_link_to_ssb’] == ‘Y’) {// share text with link
$htmlShareButtons .= ‘‘ . $strShareText . ‘‘;}
// just display the share text
else {// share text
$htmlShareButtons .= $strShareText;}
// add a line break if set to above
($arrSettings[‘ssba_text_placement’] == ‘above’ ? $htmlShareButtons .= ‘<br/>’ : NULL);}
// use wordpress functions for page/post details
$urlCurrentPage = get_permalink($post->ID);
$strPageTitle = get_the_title($post->ID);// strip any unwanted tags from the page title
$strPageTitle = esc_attr(strip_tags($strPageTitle));// the buttons!
$htmlShareButtons.= get_share_buttons($arrSettings, $urlCurrentPage, $strPageTitle, $intPostID);// add custom text if set and set to placement right or below
if (($strShareText != ”) && ($arrSettings[‘ssba_text_placement’] == ‘right’ || $arrSettings[‘ssba_text_placement’] ==’below’)) {// add a line break if set to above
($arrSettings[‘ssba_text_placement’] == ‘below’ ? $htmlShareButtons .= ‘<br/>’ : NULL);// check if user has checked share link option
if ($arrSettings[‘ssba_link_to_ssb’] == ‘Y’) {// share text with link
$htmlShareButtons .= ‘‘ . $strShareText . ‘‘;}
// just display the share text
else {// share text
$htmlShareButtons .= $strShareText;}
}
// close center if set
$htmlShareButtons.= ‘</div>’;
$htmlShareButtons.= ‘</div>’;$htmlContent = $htmlShareButtons;
// display share buttons
echo $htmlContent;}
}
3. modify the function show_share_buttons to do nothing for archive/category pages – changes go right after settings are fetched.
// get sbba settings
$arrSettings = get_ssba_settings();// added @ v6.3.4 to separate excerpts/archives functionality
if ((is_category() || is_archive() || is_front_page()) && !isset($arrSettings[‘ssba_excerpts’])) return $content;// modified @ v6.3.4 to separate excerpts/archives functionality
// placement on pages/posts/categories/archives/homepage
if ((!is_home() && !is_front_page() && is_page() && $arrSettings[‘ssba_pages’] == ‘Y’)
|| (is_single() && $arrSettings[‘ssba_posts’] == ‘Y’)
|| (is_front_page() && $arrSettings[‘ssba_homepage’] == ‘Y’)
|| ($arrSettings[‘ssba_excerpts’] == ‘Y’ && !is_page() && !is_single())
|| $booShortCode == TRUE)
{
- The topic ‘confusing functionality – excerpts and categories/archives’ is closed to new replies.