Home › Forums › Legacy Support › Support queries › How-to & Troubleshooting › Display custom course field inside course pages
- This topic has 18 replies, 3 voices, and was last updated 5 years, 11 months ago by Diana.
-
AuthorPosts
-
April 25, 2018 at 12:24 am #154132Dmit865SpectatorHi there! I know how to add a custom field for the course, but how do I display it's content (say, it will be a link) within the student course pages on units, quizzes and other pages? In fact, I would even considering displaying this custom link on the in-course sidebar menu that allows to navigate between course content. Thanks!April 25, 2018 at 10:24 am #154204DianaParticipant@Dmit865, Please follow this tip: https://wplms.io/support/knowledge-base/add-custom-content-in-attachment-area-of-units/April 26, 2018 at 12:45 am #154282Dmit865SpectatorThanks! How about doing the same with course-related field, not unit-related (so we don't need to input the same link for every unit, it is the same for the course).April 26, 2018 at 10:52 am #154334DianaParticipant@Dmit865, For the course sidebar, you can add a custom link which will be similar for all courses from wp-admin > LMS > Settings > Course Settings > Add Custom linkApril 27, 2018 at 12:14 am #154402Dmit865Spectator@Diana, I would like to have a custom link like here https://wplms.io/support/knowledge-base/add-custom-content-in-attachment-area-of-units/ but not having to set it up for each unit individually. For that I need a way to access course-level field from the code provided on the link.April 27, 2018 at 8:39 am #154446DianaParticipant@Dmit865, add_filter('wplms_unit_metabox','wplms_custom_link'); function wplms_custom_link($link){ $prefix = 'vibe_'; $link[]=array( // Text Input 'label' => __('Link for playground','vibe-customtypes'), // <label> 'desc' => __('Put link on the playground button','vibe-customtypes'), // description 'id' => $prefix.'pglink', // field id and name 'type' => 'text' // type of field ); return $link; } //Shows button in attachment area in unit function bp_course_get_unit_attachments($id){ $link="https://wplms.io/support/knowledge-base/add-custom-content-in-attachment-area-of-units/"; if(isset( $link) && !empty($link)){ echo '<FORM> <INPUT Type="BUTTON" Value="CODEBASE" class="button" Onclick="window.location.href=\''.$link.'\'"> <style> .button{ height: 60px; width: 190px; font: 16px; } </style> </FORM>'; } } From this code you need not to set the link for each unit. All the unit will access the same linkApril 27, 2018 at 11:50 pm #154534Dmit865Spectator@Diana, Thanks! I am sorry for bothering you, but your solution, judging by the code above, offers the same pre-coded link for all courses (it is stored in $link variable). I need the link to be different for each course, preferably inputed by the instructor while editing the course. To bring some context: this link will point to a messenger chat of the course and it may differ quite a lot, so it's hard to hardcode. Better have instructors put the link to the chat in the custom course field, and then have this link displayed on all course elemenets like units, quizess, etc. The code provided here is almost perfect expect it adds a custom field for each unit and I would like to use a custom field for the whole course (because the chat link is the same for one course and I don't want instructor to have to copy it all the time for each unit. Thanks again!April 28, 2018 at 10:54 am #154591Anshuman SahuKeymasterAplogies for the confusion . Please remove the above code if added and add this given code in your wplms-customizer.php file in wplms customizer plugin : //Add custom metabox in unit add_filter('wplms_course_metabox','wplms_custom_link'); function wplms_custom_link($link){ $prefix = 'vibe_'; $link[]=array( // Text Input 'label' => __('Link for playground','vibe-customtypes'), // <label> 'desc' => __('Put link on the playground button','vibe-customtypes'), // description 'id' => $prefix.'pglink', // field id and name 'type' => 'text' // type of field ); return $link; } add_action('wplms_after_every_unit','bp_course_get_unit_attachments'); function bp_course_get_unit_attachments($id){ if(function_exists('bp_course_get_unit_course_id')){ $course_id = bp_course_get_unit_course_id($id); } $link=get_post_meta($course_id,'vibe_pglink',true); if(isset( $link) && !empty($link)){ echo '<FORM> <INPUT Type="BUTTON" Value="CODEBASE" class="button" Onclick="window.location.href=\''.$link.'\'"> <style> .button{ height: 60px; width: 190px; font: 16px; } </style> </FORM>'; } }April 29, 2018 at 11:45 am #154649Dmit865SpectatorWorked, thanks! Only now the buttons is added two times for some reason. One after another in the attachments area...April 30, 2018 at 7:19 am #154697DianaParticipant@Dmit865, Can you please share the admin credentials with course URL in a private reply here to check this on your site. If you have added the code after removing the previous one then the button should appear only onceApril 30, 2018 at 12:56 pm #154755Dmit865SpectatorThis reply has been marked as private.May 1, 2018 at 5:56 am #154864DianaParticipantThis reply has been marked as private.May 1, 2018 at 7:45 pm #154999Dmit865SpectatorThis reply has been marked as private.May 2, 2018 at 10:18 am #155106DianaParticipant@Dmit865, Will Let you know after fixing this on your site.May 7, 2018 at 8:52 pm #155692Dmit865Spectator@Diana, Any luck?
-
AuthorPosts
- The topic ‘Display custom course field inside course pages’ is closed to new replies.