John Davidson

php - Shortcode always showing at the top of the wordpress (before post)

0 comments
Message:


I'm new to WP plugin development and found out that my shortcode is showing at the top of the page, but I want to include it anywhere in the post (not at the TOP).


My code:


function getLotoSecond() {
$html = file_get_contents_curl('URL__ADDRESS');

// List
$start = stripos($html, '<ul id="results-2" class="results-items">');
$end = stripos($html, '</ul>', $offset = $start);
$length = $end - $start;

$list = substr($html, $start, $length);
//--

// Regex
preg_match_all('(<label for="LotoPart_C2_([1-6]|Additional)">([0-9]|[1-9][0-9])<\/label>)', $list, $matches);
$items = $matches[2];
//--

// Output
echo '<ul>';
for($i = 0; $i < 7; $i++) {
if($i == 6) {
echo '<li style="width:30px;height:30px;border-radius:5px;background-color:#F4A024;color:white;font-size:20px;text-align:center;line-height:30px;display:inline-block;margin:0px 5px 5px 0px;">' . $items[$i] . '</li>';
} else {
echo '<li style="width:30px;height:30px;border-radius:5px;background-color:#294A70;color:white;font-size:20px;text-align:center;line-height:30px;display:inline-block;margin:0px 5px 5px 0px;">' . $items[$i] . '</li>';
}
}
echo '</ul>';
//--
}

And then:


function main($atts) {
if($atts["type"] == "loto-prvy") {
getLotoFirst();
} else if($atts["type"] == "loto-druhy") {
getLotoSecond();
}
}

add_shortcode('tipo', 'main');

What should be the problem here?



My Answer:
    ');
    $end = stripos($html, '
', $start);
$list = substr($html, $start, $end - $start + 5);
return $list;
}
function lotoSecond_shortcode() {
$list = getLotoSecond();
return $list;
}
add_shortcode('lotoSecond', 'lotoSecond_shortcode');
You can use the shortcode [lotoSecond] in your post content to display the list generated by the getLotoSecond() function. Make sure to place the shortcode within the post content where you want the list to appear.

Rate this post

4 of 5 based on 1780 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us