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ā€¢2y 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
ChrisBarinOPā€¢2y 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ā€¢2y 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
ChrisBarinOPā€¢2y ago
awesome
Jochem
Jochemā€¢2y ago
the bit you need to replace starts at line 109 in your pastebin and ends at 126
ChrisBarin
ChrisBarinOPā€¢2y ago
now testing it.
ChrisBarin
ChrisBarinOPā€¢2y ago
I messed something up
ChrisBarin
ChrisBarinOPā€¢2y ago
ChrisBarin
ChrisBarinOPā€¢2y ago
the other bits underneath broke
Jochem
Jochemā€¢2y ago
you removed the <?php on line 128 as well, you need that
ChrisBarin
ChrisBarinOPā€¢2y 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ā€¢2y ago
no worries!
Want results from more Discord servers?
Add your server