Create a list of links in PHP?

Hi, I have this page https://chrisbarin.com/membership-account/membership-checkout/?level=1 built in WordPress that's using a very tricky plugin. I have little development experience. I'm looking to replace those blue links which are automatically created with custom links and text. So I'd like to replace the code with something like <name> then <url> so that I can easily change both. Here's the entire code of that page in case it helps: https://pastebin.com/8ieDGPaD PS: I only need the blue links edited, not the array of benefits underneath.
12 Replies
Jochem
Jochemā€¢16mo ago
So you want to hard-code them in the pastebin file? They're getting fetched from the database on line 5:
$list_courses = lp_pmpro_list_courses( array( $pmpro_level ) );
$list_courses = lp_pmpro_list_courses( array( $pmpro_level ) );
likely all you need to do is change the values in the database
ChrisBarin
ChrisBarinā€¢16mo ago
not sure how to do that I'd rather just change the list from that file seems like a safer option for a beginner there are loads of implications if I change those from the database thanks for the suggestion though @jochemm
Jochem
Jochemā€¢16mo ago
ok, if you do want to just hard code things, then you have to replace the part starting with <?php and ending with ?> with the HTML you want to use:
<div class="benefits-list">
<!-- <div class="benefit">
<div class="benefit-name">Lorem, ipsum dolor.</div>
<div class="benefit-icon">āœ“</div>
</div> -->
<?php
if ( ! empty( $list_courses ) ) {
foreach ( $list_courses as $key => $course_item ) {
$content_item = '<div class="benefit"><div class="benefit-name">';
$content_item .= '<a target="_blank" href="'.get_permalink($course_item['id']).'">';
$content_item .= get_the_title($course_item['id']);
$content_item .= '</a></div><div class="benefit-icon">āœ“</div></div>';
// $content_item .= apply_filters( 'learn_pres_pmpro_course_header_level', '<td class="list-main item-td">' . wp_kses_post( $course_item['link'] ) . '</td>', $course_item['link'], $course_item, $key );
// $content_item .= apply_filters( 'learn_press_pmpro_course_is_level', '<td class="list-item item-td item-check">&#10003;</td>', $pmpro_level, 0, $course_item, $key );
// $content_item .= '</tr>';
// $content_item = apply_filters( 'learn_press_pmpro_course_item_checkout', $content_item, $course_item['link'], $course_item, $key );

echo $content_item;
}
}
?>
<div class="benefits-list">
<!-- <div class="benefit">
<div class="benefit-name">Lorem, ipsum dolor.</div>
<div class="benefit-icon">āœ“</div>
</div> -->
<?php
if ( ! empty( $list_courses ) ) {
foreach ( $list_courses as $key => $course_item ) {
$content_item = '<div class="benefit"><div class="benefit-name">';
$content_item .= '<a target="_blank" href="'.get_permalink($course_item['id']).'">';
$content_item .= get_the_title($course_item['id']);
$content_item .= '</a></div><div class="benefit-icon">āœ“</div></div>';
// $content_item .= apply_filters( 'learn_pres_pmpro_course_header_level', '<td class="list-main item-td">' . wp_kses_post( $course_item['link'] ) . '</td>', $course_item['link'], $course_item, $key );
// $content_item .= apply_filters( 'learn_press_pmpro_course_is_level', '<td class="list-item item-td item-check">&#10003;</td>', $pmpro_level, 0, $course_item, $key );
// $content_item .= '</tr>';
// $content_item = apply_filters( 'learn_press_pmpro_course_item_checkout', $content_item, $course_item['link'], $course_item, $key );

echo $content_item;
}
}
?>
What it's outputting right now is this:
<div class="benefit">
<div class="benefit-name">
<a target="_blank" href="LINK_TO_THE_COURSE">TITLE_OF_THE_COURSE</a>
</div>
<div class="benefit-icon">āœ“</div>
</div>
<div class="benefit">
<div class="benefit-name">
<a target="_blank" href="LINK_TO_THE_COURSE">TITLE_OF_THE_COURSE</a>
</div>
<div class="benefit-icon">āœ“</div>
</div>
Just repeat that how ever many times you need, and replace LINK_TO_THE_COURSE and TITLE_OF_THE_COURSE with the appropriate values
ChrisBarin
ChrisBarinā€¢16mo ago
awesome
Jochem
Jochemā€¢16mo ago
the bit you need to replace starts at line 109 in your pastebin and ends at 126
ChrisBarin
ChrisBarinā€¢16mo ago
now testing it.
ChrisBarin
ChrisBarinā€¢16mo ago
I messed something up
ChrisBarin
ChrisBarinā€¢16mo ago
ChrisBarin
ChrisBarinā€¢16mo ago
the other bits underneath broke
Jochem
Jochemā€¢16mo ago
you removed the <?php on line 128 as well, you need that
ChrisBarin
ChrisBarinā€¢16mo ago
do I keep the <?php from 109 though? and the answer is 'no' šŸ˜„ works! thanks a lot! you're a life saver I love learning this stuff
Jochem
Jochemā€¢16mo ago
no worries!