WP event manager widget only show if there is some events - wordpress

i want to show event title if there is some events, if no event is there i dont want to show event title. how can i solve this problem, please help me. iam using Event Manager plugin.sorry for my bad english

Step 1 : Inside your WP site there is the following path: \site.com\wp-content\themes\theme_name\functions.php
*In case of not having this file you created.
Step 2 : Please insert into file functions.php the following code:
<?php
function em_mod_custom_events_list(){
$events = EM_Events::get(array('scope'=>'future','limit'=>10));
?>
<table>
<tbody>
<?php
$start = false;
$limit = 3;
$count = 1;
foreach( $events as $EM_Event ){
if ( !empty($EM_Event->event_name) ){
?>
<?php if ( !$start ) { ?>
<tr>
<?php $start = true; ?>
<?php } ?>
<td><?php echo $EM_Event->output("#_EVENTLINK"); ?></td>
<?php
if ( $count == $limit ){
?>
</tr>
<?php
$start = false;
$count = 1;
}else{
$count++;
}
?>
<?php
}
}
?>
</tbody>
</table>
<?php
}
Step 3 : Save file and Test
1) Using templates --> http://wp-events-plugin.com/documentation/using-template-files
2) Create your own page event --> http://wp-events-plugin.com/tutorials/create-custom-event-information-pages/
The documentation is quite clear and you can help.

Related

Print serialized data from phpmyadmin saved using cf7db

I want to build a custom php page that shown registered user from wp,the data saved from wp is a serialized data and i got problem to display. btw i am using contact form 7 database plugin.
i keep getting explode() expect parameter to be string and getting error on line 10.
<?php
//connect database
$conn=new mysqli("localhost","root","","testsaja2");
//call a field from table
$sql= "select form_value from wp_db7_forms";
$result=mysqli_query($conn,$sql);
while($string=mysqli_fetch_array($result));
$explode = explode(PHP_EOL, $string);
foreach ($explode as $line) {
?>
<?php
foreach (unserialize($line) as $item => $value){
?>
<tr>
<td><b><?php echo $item . ": ";?></b></td>
<td><?php if ($value == 'email'){
foreach ($value as $data) {
echo $data ;
}
}
else {
echo $value;
}
?> </td>
</tr>
<br>
<?php } ?>
</table>
<?php } ?>
Modify your code to this.
<?php
//connect database
$conn=new mysqli("localhost","root","","testsaja2");
//call a field from table
$sql= "select form_value from wp_db7_forms";
$result=mysqli_query($conn,$sql);
while($string=mysqli_fetch_array($result)){
$unserialize = unserialize($string['form_value']);
foreach ($unserialize as $item => $value){
?>
<tr>
<td><b><?php echo $item . ": ";?></b></td>
<td><?php echo $value; ?> </td>
</tr>
<?php
} }?>
</table>

wp post metadata showing in backend but not frontend / same code

Situation:
using a php file (table_template.php) with include_once to show meta data. Using this template in the backend (inside a metabox) shows everything as it should - using the same template on the frontend (inside a post) the table metadata do not show (but other meta data from custom fields do).
var dump in the backend:
string(65) "[["test value 1","test value 2","test value 3"],["test value a","test value b","test value c"]]"
var dump on the frontend:
string(6) "[[""]]"
code from table_template.php:
<?php
/* TEMPLATE TO RENDER THE TABLE (AS PREVIEW) IN THE BACKEND AND FRONTEND */
global $post;
$table_meta = get_post_meta( $post->ID, 'psg_table_meta', true ) ?
get_post_meta( $post->ID, 'psg_table_meta', true ) : '[[""]]';
$t = json_decode( $table_meta );
$c_id = get_post_meta( $post->ID );
$c = get_post( $c_id );
?>
<div class="psg_box_table">
<table class="psg_table ">
<thead>
<tr>
<?php foreach ( $t[ 0 ] as $col ): ?>
<th>
<?php echo $col; ?>
</th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<?php foreach ( $t as $idx => $row ): ?>
<?php if ( $idx == 0 )
continue; ?>
<tr>
<?php foreach ( $row as $col ): ?>
<td>
<div class="psg_table_content">
<?php echo str_replace( '"', '"', $col ) ?>
</div>
</td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<!--END SIZING CHART TABLE -->
How i load the Template:
include_once( "table_template.php" );
If you are using the template inside loop of WP_Query, then replace
$post->ID
with
get_the_ID();
Also check the psg_table_meta key is correct one.
The issue was, that i should not check for the postID (the table meta data is not directly in the post, but in a selected/linked post within it. So i had to replace
$table_meta = get_post_meta( $post->ID, 'psg_table_meta', true ) ?
with
$table_meta = get_post_meta( $psg_selected, 'psg_table_meta', true ) ?

Wordpress is_page_template query

i use a Plug-in on my wordpress site which uses a query to show search results, thats the code of the query:
if ( $query->have_posts() )
{
?>
<?php echo $query->found_posts; ?> Ergebnisse gefunden<br />
<?php
while ($query->have_posts())
{
$query->the_post();
?>
<div>
<?php if ( has_post_thumbnail() ) { echo '<p>'; the_post_thumbnail("small"); echo '</p>'; } ?>
<h2><?php the_title(); ?></h2>
</div>
<?php
}
?>
Page <?php echo $query->query['paged']; ?> of <?php echo $query->max_num_pages; ?><br />
Previous | Next
<?php
}
else
{
echo "No Results Found";
}
The search should only display results from pages who uses a specific page template (mytemplate.php)
I found the Docs http://codex.wordpress.org/Function_Reference/is_page_template who explain this, but i dont get it to work inside the above query.
any help would be nice :) thx
Please do as below.
if ( is_page_template( '{enter the name of page template with extension}' ) ) {
// Enter your if code here
} else {
// Enter your else code here.
}
For this code to work you must select the page template option while creating the page in WordPress Admin Interface.

How to remove ducplicate tags from custom tag list?

I have this code to display the tags which are used in the current category, includes child categories:
if (is_category( )) {
$cat = get_query_var('cat');
$yourcat = get_category ($cat);
}
query_posts('category_name='.$yourcat->slug.'');
if (have_posts()) : while (have_posts()) : the_post();
if( get_the_tag_list() ){
echo $posttags = get_the_tag_list('<li>','</li><li>','</li>');
}
endwhile; endif;
wp_reset_query();
Is it possible to remove duplicate tags? Right now the code shows some tags multiple times instead of once.
Another question about this code: How can I output each tag like this to create a checkbox form?
<input type="radio" name="tag" value="tag1" <?php if((isset($_GET["tag"])) && $_GET["tag"] == "tag1") { echo "checked";}?>> Tag1<br>
Hopefully someone can help me with this. Thanks in advance!
Update:
I forgot to mention that I use the code if((isset($_GET["tag"])) && $_GET["tag"] == "tag1") { echo "checked";} at the end of the input field to check the checkbox when the tag is used, but if I use that code (which works in html) the page don't display properly.
I've modified your code a bit, but now you have an array of tag id's which you can use for any purpose, for ex. list added below.
if (is_category()){
$cat = get_query_var('cat');
$yourcat = get_category ($cat);
}
$tag_IDs = array();
query_posts('category_name='.$yourcat->slug);
if (have_posts()) : while (have_posts()) : the_post();
$posttags = get_the_tags();
if ($posttags):
foreach($posttags as $tag) {
if (!in_array($tag->term_id , $tag_IDs)):
$tag_IDs[] = $tag->term_id;
$tag_names[$tag->term_id] = $tag->name;
endif;
}
endif;
endwhile; endif;
wp_reset_query();
echo "<ul>";
foreach($tag_IDs as $tag_ID){
echo ''.$tag_names[$tag_ID].'';
}
echo "</ul>";

Wordpress: How to Put a Function inside PHP?

with
<?php
if (is_category())
echo single_cat_title();
?>
i can show up the current category title..
how can i insert the tag single_cat_title() into:
<?php
$recent = new WP_Query("cat=10&showposts=4"); while($recent->have_posts()) : $recent->the_post();
if (in_category(10) && in_category(**Insert Here**)) { ?>
i tried it with
if (in_category(10) && in_category('.single_cat_title.')) { ?>
but no chance...
thank you!
Probably best to put it into a variable
$cat_title = single_cat_title();
then
if (in_category(10) && in_category($cat_title)) { ?>

Resources