Advertisement:

Author Topic: custom.php breadcrumb  (Read 548 times)

armaniworld

  • Newbie
  • *
  • Posts: 23
  • Gwolla.co.uk
custom.php breadcrumb
« on: September 24, 2018, 03:27:00 am »
how can i change the breadcrumb on custom pages (custom.php) from

mysite > custom

to mysite > something else

thanks.


fog

  • Hero Member
  • *****
  • Posts: 1062
Re: custom.php breadcrumb
« Reply #1 on: September 24, 2018, 07:54:57 pm »
Hi, depends of your theme, and / or if is a custom page of a plugin to add something more on your breadcrumbs code?

Take note, if you using bender theme, the breadcrumbs are on header.php file. If you need something more custom, you need use conditionals to detect current page of user.

On your theme you have too the user-custom.php, that file is for user custom pages (user dashboard).

Is better you tell more about you need to do in concrete on these current pages, to get more help.

Regards

WEBmods

  • Hero Member
  • *****
  • Posts: 936
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: custom.php breadcrumb
« Reply #2 on: September 24, 2018, 10:52:04 pm »
Hello,

This topic actually motivated me to do this for my site. I found that my theme uses Osclass core breadcrumbs so I had to modify a core file.

I opened oc-includes/osclass/classes/Breadcrumb.php and located "case('custom')":

Code: [Select]
case('custom'):
    $l = array('title' => Rewrite::newInstance()->get_title());
    $this->addLevel($l);
break;

and replaced it with this:

Code: [Select]
case('custom'):
    $custom_breadcrumbs = cs_custom_breadcrumbs();
    $valid = 0;
    foreach($custom_breadcrumbs as $breadcrumb) {
        if(Params::getParam('route') == $breadcrumb['route']) {
            $l = array('title' => $breadcrumb['title']);
            $this->addLevel($l);
            $valid = 1;
        }
    }
    if(!$valid) {
        $l = array('title' => Rewrite::newInstance()->get_title());
        $this->addLevel($l);
    }
break;

After that, I created a function in functions.php of the theme:

Code: [Select]
function cs_custom_breadcrumbs() {
    $breadcrumbs = array(
        array('route' => 'upayments-user-payments', 'title' => __('Pay', 'text_translate')),
        array('route' => 'ROUTE NAME', 'title' => __('TITLE', 'THEME/PLUGIN NAME')),
    );

    return $breadcrumbs;
}

I believe there are more elegant solutions, but this works great for me.

Regards.

armaniworld

  • Newbie
  • *
  • Posts: 23
  • Gwolla.co.uk
Re: custom.php breadcrumb
« Reply #3 on: September 24, 2018, 11:29:29 pm »
works perfect for me, cant thank you enough!

fog

  • Hero Member
  • *****
  • Posts: 1062
Re: custom.php breadcrumb
« Reply #4 on: September 24, 2018, 11:54:11 pm »
Why not modify breadcrumbs only on theme? If is just to add title in the end, will be enough, and no any changes on core is needed.

Create a function on your theme to detect current page, and add your statments you will need. Call the hook of that function to breadcrumbs on your header file, and it will works.

Regards

Resta

  • Sr. Member
  • ****
  • Posts: 345
Re: custom.php breadcrumb
« Reply #5 on: September 25, 2018, 12:46:48 pm »
Patrick,

Can you please explain the last part of the code that is added to functions.php - is that for a payment plugin, right?

Based on the question by OP, what if I want to show the title for a custom page_28 with the name "Results" to show like this:
mysite > this is my page? What do I need to put in the array and if I have several custom pages, then how to do it? Thanks!
« Last Edit: September 25, 2018, 12:52:22 pm by Resta »

armaniworld

  • Newbie
  • *
  • Posts: 23
  • Gwolla.co.uk
Re: custom.php breadcrumb
« Reply #6 on: September 25, 2018, 02:44:45 pm »
the first one i think is for a plugin Patrick is using, the bottom one is blank. i had a custom page called notifications, i put the route name as notifications and the title with whatever i want the breadcrumb to display, thanks.

Resta

  • Sr. Member
  • ****
  • Posts: 345
Re: custom.php breadcrumb
« Reply #7 on: September 25, 2018, 10:25:10 pm »
Not working for me.

My custom page is:

Title: Custom Page
Internal Name : my_page
In the theme directory it is named as : page-my_page.php

In functions.php I have it like this:
        array('route' => 'page-my_page', 'title' => __('This is a custom Page', 'bender/my_page')),

What am I doing wrong?  Thanks!

WEBmods

  • Hero Member
  • *****
  • Posts: 936
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: custom.php breadcrumb
« Reply #8 on: September 26, 2018, 01:53:12 am »
Sorry, very busy lately...

@Resta, my code is currently only for custom plugin pages that use routes. In the code I provided, the first line was an example I used for Ultimate Payments plugin. There is a way for the pages added in admin, I will check and provide a solution, but later.

@fog, what you said makes a lot of sense, but I didn't notice it. :) I will try to post a theme-only solution.

Regards-

WEBmods

  • Hero Member
  • *****
  • Posts: 936
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: custom.php breadcrumb
« Reply #9 on: July 09, 2019, 02:15:18 pm »
I needed a solution without core edit this time. I found this topic and saw that I actually didn't post that solution, but I said I will. Well, more than a half year later, it's here.

Example of Violet theme and one of my plugins.

oc-content/themes/violet/header.php

Code: [Select]
<?php
if(function_exists('userreview_install') && Rewrite::newInstance()->get_location() == 'userreview') { // Use Params or Rewrite class to determine your pages.
    
userreview_breadcrumb(); // Custom plugin breadcrumb.
} else {
    
// This is default breadcrumb code.
    
$breadcrumb osc_breadcrumb('&raquo;'false);
    if( 
$breadcrumb != '') {
        echo 
$breadcrumb;
    }
}
?>


In my case, oc-content/plugins/zo_userreview/helpers/hUserReview.php. In yours probably oc-content/themes/violet/functions.php.

Code: [Select]
<?php
function userreview_breadcrumb() {
    
$breadcrumb = new Breadcrumb(); // Initialise Breadcrumb class.
    
$level1 = array(
        
'url'   => osc_base_url(),
        
'title' => osc_page_title()
    );
    
$breadcrumb->addLevel($level1); // Add first level with page title.
    
    
$route Params::getParam('route'); // Get route.
    
switch($route) { // Pick title based of route.
        
case 'userreview-add'// If route is "userreview-add".
            
$user_id Params::getParam('id');
            
$user_name userreview_get_subject();
            
            
$level2 = array(
                
'url'   => osc_user_public_profile_url($user_id), // URL
                
'title' => $user_name // Title
            
);
            
$breadcrumb->addLevel($level2); // Add second level, user name (e.g. John).
            
            
$level3 = array(
                
'title' =>  __('Add a review''zo_userreview'// Title. No URL because this is the last level.
            
);
            
$breadcrumb->addLevel($level3); // Add third level, 'All reviews'.
            
break;
        case 
'userreview-all-list':
            
$level2 = array(
                
'title' => __('All reviews''zo_userreview'// Title. No URL because this is the last level.
            
);
            
$breadcrumb->addLevel($level2); // Add second level, 'All reviews'.
            
break;
    }
    
    echo 
$breadcrumb->render(); // Show the breadcrumb.
}

@Resta, a simplified solution for you would look like this. Bender theme.

oc-content/themes/bender/header.php

Code: [Select]
    <?php if(Params::getParam('slug') == 'YOUR PAGE SLUG') {
        
$breadcrumb = new Breadcrumb();
        
$level1 = array(
            
'url'   => osc_base_url(),
            
'title' => osc_page_title()
        );
        
$breadcrumb->addLevel($level1); // Add page title - first level.
        
$breadcrumb = new Breadcrumb();
        
$level1 = array(
            
'title' => 'YOUR CUSTOM TITLE' // Only TITLE, as this is last level.
        
);
        
$breadcrumb->addLevel($level1);
        
$breadcrumb->render();
        
?>

        <div class="breadcrumb">
            <div class="clear"></div>
        </div>
    <?php } else {
        
$breadcrumb osc_breadcrumb('&raquo;'falseget_breadcrumb_lang());
        if( 
$breadcrumb !== '') { ?>

        <div class="breadcrumb">
            <?php echo $breadcrumb?>
            <div class="clear"></div>
        </div>
        <?php }
    } 
?>


Sorry for waiting and messy code...

Regards.
« Last Edit: July 09, 2019, 02:17:02 pm by patrickFromCroatia »