implement multiple slider instances through wordpress plugin - php

i have customised the smooth div scroll jquery plugin (http://smoothdivscroll.com/) and implemented it in wordpress as a wordpress plugin along with an options page you can view the slider here http://dev.linuxfreakz.com/?page_id=2 , i have created an options page in wordpress admin which has 4 options to select the slider title , background and arrows color and category of posts . the slides are wordpress posts and the images inside them are their featured images . the slider can be currently used with a shortcode , this is all fine and working .
the problem is that now i am supposed to add multiple sliders that can have different options selected and can be used on a single page through the options page and i am confused as how to get this done . can some wordpress guru please point me in the right direction i am really running out of time here , i don't need the whole code just an idea as how i could actually get this done and i am pretty good at php and wordpress myself usually .
any help would be appreciated , thank you .
here is the code that pulls the posts and generates the slider that i am currently using
function sds_display_slider() {
global $post;
$sds_category2 = (get_option('sds_category') != false) ? get_option('sds_category') : 1;
$sds_title2 = (get_option('sds_title') != '') ? get_option('sds_title') : 'Smooth Slider';
$sds_bgcolor2 = (get_option('sds_bgcolor') != '') ? get_option('sds_bgcolor') : '#dedede';
$sds_navcolor2 = (get_option('sds_navcolor') != '') ? get_option('sds_navcolor') : '#9e1b32' ;
$plugins_url = plugins_url();
echo '<div id="carousel" style="background-color:'.$sds_bgcolor2.'!important;">
<style>
div.scrollingHotSpotLeft {background-color:'.$sds_navcolor2.';}
div.scrollingHotSpotRight{background-color:'.$sds_navcolor2.';}
</style>
<h2>'.$sds_title2.'</h2>
<div id="makeMeScrollable">';
query_posts('post_type=post&posts_per_page=-1&cat='.$sds_category2.'&order=ASC');
if ( have_posts() ) :while ( have_posts() ) : the_post();
$img_attached_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'medium');
$img_attached = $img_attached_url[0];
$post_heading = get_the_title($post->ID);
$post_text = substr(get_the_excerpt(),0,180)."...";
$link = get_permalink($post->ID);
echo '<div class="contentBox">
<a href="'.$link.'">
<img src="'.$img_attached.'"></a><br>
<h2>'.$post_heading.'</h2>
<p>'.$post_text.'</p>
</div>';
endwhile;
endif;wp_reset_query();
echo '</div>
</div>';
}

Try http://wordpress.org/plugins/meta-box/ and put your options page inside.

Related

ACF page while loop breaks footer while loop

So basically i have a main page and a footer page. Both are seperate .php files.
Im using ACF for this site.
Following the documentation, ive created a while loop for my 'flexible content' in the main page and it works, displaying all the data that gets looped and hooked from the CMS input fields.
My Problem is in the footer, i have a while loop that displays links, but it wont display unless i remove the while loop from the main page, then the links display in the footer.
I honnestly dot get why this happens ive tested allot and get my head wrapped around this, please help.
Main page code:
<?php
// check if the flexible content field has rows of data
if( have_rows('flexible_content_field_name') ):
// loop through the rows of data
while ( have_rows('flexible_content_field_name') ) : the_row();
// check current row layout
if( get_row_layout() == 'gallery' ):
// check if the nested repeater field has rows of data
if( have_rows('images') ):
echo '<ul>';
// loop through the rows of data
while ( have_rows('images') ) : the_row();
$image = get_sub_field('image');
echo '<li><img src="' . $image['url'] . '" alt="' . $image['alt'] . '" /></li>';
endwhile;
echo '</ul>';
endif;
endif;
endwhile;
else :
// no layouts found
endif;
?>
<?php get_footer(); ?>
Footer Code:
<div class="links">
<?php
if( have_rows('footer_page_links', 'option') ):
var_dump("test");
while( have_rows('footer_page_links', 'option') ): the_row();
?>
<p><?php the_sub_field('footer_link_name'); ?></p>
<?php endwhile; ?>
<?php endif; ?>
</div>
<?php wp_footer(); ?>
I would just like to add , not even the vardump() displays in the footer if main page while loop is implemented so it never gets inside the footer loop. The footer uses ACF option page - > LINK
Also all other option fields in footer displays, if its not within the while loop. I have removed the main page while loop then the footer while loop works, and this only happens with flexible content, my other pages with loops, that does non consists of flexible content works perfectly.
So This issue is resolved on my side, after contacting the ACF guys, they made a duplicate of what i did and could not recreate my issue.
Which got me thinking since i had the latest Wordpress (Version 4.9.7) the only difference is the hosting.
What i used on localhost was XAMP Version 3.2.2, which i did not think was the problem, but it was, so upgraded to a live server and everything works as expected, so for future ref should you run into these simple unexplained code errors, check the hosting, or upgrade.

How do you create a "next page" link in Wordpress?

I'm trying to add a button to my site which links to the next page of posts. I'm looking for a way to add an HTML link to the button so it actually works.
http://codex.wordpress.org/Template_Tags/wp_link_pages
I believe that explains what I want, but I'm not having any luck trying to get those snippets to work.
My button looks like:
Next Page
How can I link the button to the next page function in Wordpress?
EDIT:
My problem is I can't figure out how to associate this code with a button.
There are two 'built-in' ways of doing this in Wordpress:
1) If you need access to the link as a PHP variable, try Using get_next_posts_link
<?php $nextLink = get_next_posts_link( $label , $max_pages ); ?>
<?php $previousLink = get_previous_posts_link( $label ); ?>
From here the links are stored in variables and you can do whatever you'd like with them.
2) Otherwise use these:
<?php next_posts_link( $label , $max_pages ); ?>
<?php previous_posts_link( $label ); ?>
Where $label is the name of the link ( "Next Page" in your case ) and $max_pages is the max number of pages (if you want a limit), that the link shows up on.
If you want to style these, without having to enclose them inside another DIV, use Wordpress Filters
function apply_my_next_link_style ( ){
return 'class="button"';
}
apply_filters( 'next_posts_link_attributes', 'apply_my_next_link_style' )
3) If you need even more control you can try this, from the source code for the above functions:
if ( !is_single() ) {
echo '<a href="' . next_posts( 0, false ) . "\" $attr>" . preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&$1', "Next Page") . '</a>';
}
Also, I would suggest asking these types of questions over at wordpress.stackexchange.com
Is necesary Snippets , visit this and this solve
<?php next_posts_link('Older Posts'); ?>
<?php previous_posts_link('Newer Posts'); ?>

PHP, Advanced Custom Fields, Wordpress, if statement

What am I doing wrong? Just to warn you this is my first attempt at php so pardon my ignorance ;)
Currently using Wordpress with a plugin called Advanced Custom Fields. Which allows you to create custom field options in the backend of wordpress.
http://plugins.elliotcondon.com/advanced-custom-fields/
I am trying to get a div to hide if the value of the Advanced Custom Field "Available" (which is a select list) is set to "No". The div is a marker for the 10 available apartments that overlays a map. Currently it displays all 10 markers whether it's availability is set to "No" or "Yes".
$i = 201;
$available = get_field('available');
while ($i <= 210) :
if ($available == 'No') {
echo '<div id="apt-' . $i . '" class="map-marker" style="display:none;"></div>';
} elseif ($available) {
echo '<div id="apt-' . $i . '" class="map-marker">';
echo $i++;
echo'</div>';
}
endwhile;
what are you trying to accomplish here? the get_field function is a per post in the loop method, so you would need to be iterating over the whole posts collection with the
while ($loop->have_posts()) : $loop->the_post();
if you're not using a custom loop you would leave off the $loop-> part.
you probably need to post the whole page template. you might just need to do some studying on wordpress about the loop and how it works.

How to create permalinks without single pages in wordpress?

I'm creating my own wordpress theme which is a bit different because it will not have single pages (or atleast, no single page will be reachable). The whole website contains just the homepage (with the loop) and previous posts pages.
I want to link to individual posts inside the loop like site.com#post-124 or site.com/paged=5#post-214.
I already created a function that does this:
function getPermalink($id,$postsPerPage) {
$postNumber = Get_Post_Number($id);
//a function that get's the post number based on
//the chronical order of published posts.
$page = floor(($postNumber - 1) / $postsPerPage);
$url = get_option('home');
if($page > 0) {
$url .= '/?paged=' . ($page + (1 - floor($page / 5)));
}
$url .= '#post-' . $id;
return $url;
}
You can see it live here: http://mijnrealiteit.nl (the previous posts pages are replaced by an infite scroll plugin).
This works, however it breaks when I start adding posts because all the posts before will get shifted back to pages further away (this makes the link invalid).
The way I see it there are two possible solutions:
Change the permalinkstructure to display paging backwards (so x.com/paged=231 becomes the first 'previous' page. However this is not userfriendly.
Make links with just the ID and let wordpress handle custom redirection to the page at that current point in time.
Are there better alternatives? I'm sure this is already solved somewhere, I just couldn't find it.
I got pushed in the right direction by a friend, I build it quite easily using option 2:
The getPermalink function is now much simpler:
function getPermalink($id) {
return get_option('home') . '/?f=' . $id;
}
I didn't make any custom redirection, I just checked at the homepage for a an 'f' being passed in the GET request:
$perma = $_GET['f'];
if(isset($perma) && !is_paged()) {
$customposts = get_posts('p=' . $perma );
foreach( $customposts as $post ) :
setup_postdata($post); ?>
//load the post
<?php endforeach;
}?>
If that is true the post will be fetched using the get_posts function by Wordpress. I also check the (normal) loop for the post that already has been served:
<?php while (have_posts()) : the_post();
if(get_the_ID() != $perma) { ?>
//load the post
<?php } endwhile; ?>

Wordpress, PodCMS and Search

I have a WordPress site for a client. He owns a video store, and I made a site for him to update the list of movies, usually just the "new this week" movies.
I used PodCMS as an easy way for him to upload movies and then display them. No need for him to even create posts. Works really well, it's a great extension, I'm just having some issues.
The Pod has a field where you insert the release date. 2010-04-20
Then there is a Pod page/template combo that calls the movies with a certain release date like this:
$date = pods_url_variable('last');
He then just creates a blank WP page with the slug 2010-04-20
So when you open that page, the Pod page/template reads that slug and renders a list of the appropriate movies.
My problem:
I need these to be searchable. Is this possible.
I'm also open to suggestions on other ways to go about making this site work. I need it to be as simple as that. Uploads some movies and creates a new page. Then the rest is done automatically.
A PodsCMS search is nothing more than a mySQL table search for the search term. You can search the title, body, pretty much anything. Here's an example:
Note: I'm using "whatever" as the pod info. I'm also forming a string that goes into the $where position which comprises the various pods variables I want to search on. Also, I'm assuming pagination using the Pods pagination controls but I want that variable carried across the pages so I can offset.
<?php
$search_term = $_GET["s"];
$paged = get_query_var('paged');
$page_number = $_GET['pg'];
?>
<h1>
Results for "<?php echo $search_term; ?>"<?php if($page_number > 1){ ?> (Continued)<?php } ?><?php if($paged > 1){ ?> (Continued)<?php } ?>
</h1>
<?php if($paged <= 1){ ?>
<h2>Results in Whatever...</h2>
<?php
$whateverSentence = "(t.name LIKE '%" .$search_term. "%') || (t.whatever LIKE '%" .$search_term. "%')";
$whatever = new Pod('whatever');
$whatever->findRecords($orderby = 't.whatever DESC', $rows_per_page = 5, $where = $whateverSentence, $sql = null);
$total_whatever = $whatever->getTotalRows();
?>
<?php if( $total_whatever >0 ) : ?>
<?php while ( $whatever->fetchRecord() ) : ?>
<?php
// Set Variables
$whatever_ID = $whatever->get_field('id');
$whatever_Permalink = $whatever->get_field('slug');
$whatever_Name = $whatever->get_field('name');
?>
Code that echos the pods variables and represents the search result
<?php endwhile ?>
<?php else: ?>
<p>Sorry, no results found for that search.</p>
<?php endelse; endif ?>
<?php echo $whatever->getPagination($label = '<span class="pagination-text">Go to page:</span>'); ?>
<?php } ?>
So you need the WordPress page content - the list of movies - to be searchable?
WP doesn't search pages natively, but will with WordPress › Search Everything « WordPress Plugins and search better with WordPress › Relevanssi « WordPress Plugins

Categories