Wordpress image Thumbnail - image

I'm trying to find a solution how to display only the thumbnail imagen on the main page of the blog and inside the post display all other images atached to the post.
I've googled it with no luck... Can anyone help?
Here you can see what I mean: blog.turdidesigns.com
I'm new to wordpress, so I appologise if this is a stupid question.
Thanks,

in your index.php file replace the_content(); with the_excerpt();
Also, this might be in a loop, so make sure you replace this for articles lists (category, archive, search), not in single loop.

in my index php I don't have this...
Here is what I have:
in my theme folder infex php I only have this:
<?php get_header(); ?>
<div class="art-layout-wrapper">
<div class="art-content-layout">
<div class="art-content-layout-row">
<div class="art-layout-cell art-content">
<?php get_sidebar('top'); ?>
<?php
if(have_posts()) {
/* Display navigation to next/previous pages when applicable */
if ( theme_get_option('theme_' . (theme_is_home() ? 'home_' : '') . 'top_posts_navigation' ) ) {
theme_page_navigation();
}
/* Start the Loop */
while (have_posts()) {
the_post();
get_template_part('content', get_post_format());
}
/* Display navigation to next/previous pages when applicable */
if (theme_get_option('theme_bottom_posts_navigation')) {
theme_page_navigation();
}
} else {
theme_404_content();
}
?>
<?php get_sidebar('bottom'); ?>
<div class="cleared"></div>
</div>
<div class="art-layout-cell art-sidebar1">
<?php get_sidebar('default'); ?>
<div class="cleared"></div>
</div>
</div>
</div>
</div>
<div class="cleared"></div>
<?php get_footer(); ?>
I did this theme with Artisteer, so don't judge me too much ;)

Sorry for the late reply !!!
Here is the content.php code:
<?php
/**
*
* content*.php
*
* The post format template. You can change the structure of your posts or add/remove post elements here.
*
* 'id' - post id
* 'class' - post class
* 'thumbnail' - post icon
* 'title' - post title
* 'before' - post header metadata
* 'content' - post content
* 'after' - post footer metadata
*
* To create a new custom post format template you must create a file "content-YourTemplateName.php"
* Then copy the contents of the existing content.php into your file and edit it the way you want.
*
* Change an existing get_template_part() function as follows:
* get_template_part('content', 'YourTemplateName');
*
*/
global $post;
theme_post_wrapper(
array(
'id' => theme_get_post_id(),
'class' => theme_get_post_class(),
'thumbnail' => theme_get_post_thumbnail(),
'title' => '' . get_the_title() . '',
'heading' => theme_get_option('theme_'.(is_single()?'single':'posts').'_article_title_tag'),
'before' => theme_get_metadata_icons( 'date,author,edit', 'header' ),
'content' => theme_get_excerpt(),
'after' => theme_get_metadata_icons( 'category,tag,comments', 'footer' )
)
);
?>

Related

Jaxon doesn´t return anything on response

Please, can anyone help?
I´m starting to use jaxon 3, planning to migrate from xajax. On a php7.3 plataform, I made a simple code, just to load jaxon and run a single alert script, but its returning nothing on browser. There are no errors on server log and no info on browser, no even on the chrome debug console.
Here is the simple code:
<?php
require_once( 'Jaxon/vendor/autoload.php' );
use Jaxon\Jaxon;
use Jaxon\Response\Response;
$ajax = jaxon();
$ajax->setOption('core.debug.on', false);
$ajax->setOption('core.prefix.function', 'jaxon_');
$ajax->setOption('core.request.uri', 'ajax.php');
$objResponse = new Response();
$objResponse->alert('test');
return $objResponse;
echo 'tests';
?>
PS: I didn´t use the jaxon word on tag cause the editor doesn´t let me do it
I would tell you to delete the echo at the end, and try to code some functions even for testing, so you can better understand v3.
Here, check this code, it might help you, this code is tested and will work.
<?php
require_once ($_SERVER['DOCUMENT_ROOT'].'/vendor/autoload.php');
use Jaxon\Jaxon;
use Jaxon\Response\Response;
$jaxon = jaxon();
$jaxon->setOption('js.app.minify', TRUE);
$jaxon->setOption('js.lib.uri', '/vendor/jaxon-php/jaxon-js/dist');
/** ################################# */
/** using jaxon with just functions then you have to register each function
*
* call these functions like this:
* jaxon_demo1();
* jaxon_demo2();
*
* <button type="button" onclick="jaxon_demo1()"> call fn 1 </button>
* <button type="button" onclick="jaxon_demo2()"> call fn 2 </button>
*
*/
$jaxon->register(Jaxon::USER_FUNCTION, 'demo1');
$jaxon->register(Jaxon::USER_FUNCTION, 'demo2');
$jaxon->register(Jaxon::CALLABLE_FUNCTION, 'functionThatReturnsUsing_setReturnValue', ['mode' => "'synchronous'"]);
function demo1(){
$jaxonResponse = new Response();
$jaxonResponse->alert('Hello there, be sure to open browser console to see the console.log');
$jaxonResponse->script("console.log('Hello there')");
return $jaxonResponse;
}
function demo2(){
$jaxonResponse = new Response();
// <div id="theDiv"> this will be replaced </div>
$jaxonResponse->assign("theDiv","innerHTML",'Some content that can even be a template if you implement smarty or similar');
return $jaxonResponse;
}
/**
* check out https://github.com/jaxon-php/jaxon-js/issues/15
* this should work, take a look at the link provided
* also use the browser console to look the response data being returned
*/
function functionThatReturnsUsing_setReturnValue(){
$jaxonResponse = new Response();
// lets suppose you have a script like this
// <script>
// function demo3(){
// var myData = jaxon_functionThatReturnsUsing_setReturnValue();
// console.log(myData);
// }
// </script>
$someData = array(
'isValidated' => TRUE,
'str_data' => 'some data here',
'int_data' => 123,
'flt_data' => 1.23,
'row_data' => array(
'isValidated' => TRUE,
'str_data' => 'some data here',
'int_data' => 123,
'flt_data' => 1.23
)
);
$jaxonResponse->setReturnValue($someData);
$jaxonResponse->getOutput();
return $jaxonResponse;
}
if($jaxon->canProcessRequest()){
$jaxon->processRequest();
}
/**
* if you are using composer, then your composer.json should have this at least:
*
* {
* "require": {
* "jaxon-php/jaxon-core": "^3.2",
* "jaxon-php/jaxon-js": "^3.2"
* }
* }
*
*/
?>
<!DOCTYPE html>
<html lang="es">
<head>
<title>Demo jaxon</title>
<?php echo $jaxon->getCss(); ?>
</head>
<body>
<ul>
<li>demo fn 1</li>
<li>demo fn 2</li>
<li>demo fn 3</li>
</ul>
<div id="theDiv">this will be replaced</diV>
<script>
function demo3(){
var myData = jaxon_functionThatReturnsUsing_setReturnValue();
console.log(myData);
}
</script>
<?php
echo $jaxon->getJs();
echo $jaxon->getScript();
?>
</body>
</html>

Yii Framework: validate checkbox on view page

I'm new to the Yii Framework. Currently, I'm having a project which require me to use Yii framework. I would like to ask, is it possible for me to validate an attribute which is not save inside the database?
case:
I have a checkbox which require the user to tick on it in order to move to the next page. If the user doesn't tick on it, then it will prompt an error. How to I validate it in Yii format?
Can someone teach me how to change the validation below to fit Yii Format? where should the validation locate?
content in model.php
public $pdpa_agree;
public function rules()
{
array('pdpa_agree', 'required');
}
content in view.php
<?php
$form=$this->beginWidget('bootstrap.widgets.TbActiveForm',array(
'id'=>'pdpaPolicy-form',
'enableAjaxValidation'=>true,
'type'=>'horizontal',
'htmlOptions' => array(
'enctype' => 'multipart/form-data',
"autocomplete"=>"off", //turn off auto complete in FF
)
));
?>
<?php echo $data->pdpa_content; ?>
<p class="cb_pdpa" style="font-weight:bold"><?php echo $form->checkbox($data,'pdpa_agree'); ?> I have read and understood the above policies and hereby give consent for CTES to use my <pd>*personal data</pd> in accordance to the policies listed out above.</p>
<div class="form-actions">
<?php
/*$this->widget('bootstrap.widgets.TbButton', array(
'buttonType' => 'submit',
'type' => 'primary',
'label'=>$model->isNewRecord ? 'PolicyAgreement' : 'Continue Registration',
));*/
?>
<input type="button" name="submit" value="Continue Registration" onclick="validateAgreement()">
</div>
<?php $this->endWidget(); ?>
<script>
function validateAgreement()
{
if($("#pdpa_agree").is(':checked'))
{
window.location.href = 'register?sourceID=CTES';
return true;
}
else
{
alert("Please tick on the agreement checkbox in order to proceed the registration!");
return false;
}
}
</script>
How to turn to validation below to fit Yii Format?
<script>
function validateAgreement()
{
if($("#pdpa_agree").is(':checked'))
{
window.location.href = 'register?sourceID=CTES';
return true;
}
else
{
alert("Please tick on the agreement checkbox in order to proceed the registration!");
return false;
}
}
</script>
Yeah you can validate
Model.php
Delclare the variable you want to use
public $pdpa_agree;
public function rules()
{
array('pdpa_agree', 'required');
}
public function attributeLabels()
{
return array(
'pdpa_agree' => 'I have read and understood the above policies and hereby give consent for CTES to use my *personal data in accordance to the policies listed out above',
);
}
MyController.php
public function actionRegistration(){
$model = new Model();
if(isset($_POST['Model'])){
//Stuff to save Goes here
}
$this->render('registration');
}
view.php
<?php
$form=$this->beginWidget('bootstrap.widgets.TbActiveForm',array(
'id'=>'pdpaPolicy-form',
'enableAjaxValidation'=>true,
'enableClientValidation'=>true,
'type'=>'horizontal',
'htmlOptions' => array(
'enctype' => 'multipart/form-data',
"autocomplete"=>"off", //turn off auto complete in FF
)
));
?>
<?php echo $data->pdpa_content; ?>
<div class="form-actions">
$form->checkBox($model,'checkBox');
$form->labelEx($model,'checkBox');
$form->error($model,'checkBox');
</div>
<?php $this->endWidget(); ?>

Yii ClinkPager doesn't work on Ajax Request

Firstly, when the page gets loaded, ClinkPager works properly with all the paging correctly displayed.
But when Ajax Request is sent, the results get populated correctly with all the paging.
But clicking on the next or another page in the Paging, the previous data gets loaded and also paging shows different sequence.
/*Controller action to fetch the records and apply the pagination*/
//---------------------------------------------------------------
public function actionGetUser($user_id=null)
{
$user_domain= (isset($_POST['user_domain'])?$_POST['user_domain']: null);
$model=new UserSearch();
$criteria=new CDbCriteria();
//If Category/Title are also specified for search, then its an Ajax request.
if((isset($_POST['ajax_search'])) && ($_POST['ajax_search']==1))
{
//Change the search criteria accordingly
$criteria->select="*";
if($user_domain!= null)
{
//Adding criteria to search for ideas of specific domain
$criteria->addCondition("user_domain=".$usr_domain);
}
}
//Retrieve the users.
$searchData = $model->search();
//Count the no. of results retrieved.
$count=UserSearch::model()->count($criteria);
//Enable pagination
$pages=new CPagination($count);
$searchData->setPagination($pages);
$pages->applyLimit($criteria);
//Search for ideas satisfying that criteria
$models=userSearch::model()->findAll($criteria);
if((isset($_POST['ajax_search'])) && ($_POST['ajax_search']==1))
{
//Rendering the respective page
$this->renderPartial('renderOnAjax', array(
'user' => $models,
'pages' => $pages,
'user_count'=>$count
));
}
else
{
//Rendering the respective page
$this->render('render', array(
'user' => $models,
'pages' => $pages,
'user_count'=>$count
));
}
}
//------------------------------------------------------------
/*render page*/
//------------------------------------------------------------
<div>
<div class="userInfo" id="user_search_result">
<?php $this->renderPartial("renderOnAjax",array('user'=>$user, 'pages'=>$pages));?>
</div>
</div>
//------------------------------------------------------------
/*renderOnAjax Page*/
//------------------------------------------------------------
<?php
$i=0;
$count=count($user);?>
<?php while($i!=$count) {?>
<?php $row=$count[$i];?>
<div class="Box">
/*Some contain to display...*/
</div>
<?php $i++;?>
<?php } ?>
<div class="row">
<?php $this->widget('CLinkPager', array(
'pages' => $pages
));
?>
</div>
//---------------------------------------------------------
try
<?php $this->renderPartial("renderOnAjax",array('user'=>$user, 'pages'=>$pages),false,true);?>
Here is official documentioan for renderPartial
public string renderPartial(string $view, array $data=NULL, boolean $return=false, boolean $processOutput=false)
$view=string name of the view to be rendered. See getViewFile for details about how the view script is resolved.
$data=array data to be extracted into PHP variables and made available to the view script
$return=boolean whether the rendering result should be returned instead of being displayed to end users
$processOutput=boolean whether the rendering result should be postprocessed using processOutput.
{return} string the rendering result. Null if the rendering result is not required.
EDIT:
The above scheme works for ajax call renderPArtials. You should try this where you are rendering ajax request in controller action like
$this->renderPartial('renderOnAjax', array(
'user' => $models,
'pages' => $pages,
'user_count'=>$count
),false,true);

Yii, Fancybox and ajax-loaded data

I have a link that looks like
<a class="fancy" href="/site/feedback">feedback</a>
Ajax call:
$('.fancy').fancybox({
wrapCSS: 'custom-fancy',
padding: 0,
type: 'ajax'
});
On click fancybox load content wich controller send.
$this->renderPartial('_feedback')
Feedback view:
<?php
/* #var $this Controller */
/* #var $model FeedbackForm */
/* #var $form CActiveForm */
$form = $this->beginWidget('CActiveForm', array(
'id' => 'feedback-form',
'enableClientValidation' => TRUE,
)); ?>
<div><?= $form->textArea($model, 'feedback') ?></div>
<?=$form->error($model, 'feedback')?>
<? $this->widget('CCaptcha') ?>
<?=$form->textField($model, 'verifyCode', array('placeholder' => 'Captcha code'))?>
<div><?=CHtml::submitButton('Send', array('class' => 'r button'))?></div>
<? $this->endWidget() ?>
The problem is that there is no javascript/ajax validation on this loaded form. I think, it is because some Yii scripts did not loaded after ajax call (yiiActiveForm.js maybe, I don't know).
What is the best solution for this situation?
We need to set $processOutput is true as a fourth parameter. (RenderPartial postprocess default value is false.) Then only $processOutput method will insert registered client scripts into the output at appropriate places.
$this->renderPartial('view file', array(data to be available to view file), false, true);
Well, you need to load some code with javascript
$output = $this->renderPartial('_feedback', array(), true)
// you need set layout to false for render only your form
Yii::app()->clientScript->render($output);
// where you need remove jquery for prevent double initiation's jquery script
// it's not worked example!!!
preg_replace('#<script type="text/javascript" src="jquery.js"></script>#mi', '', $output);
// well, we may output
echo $output;

Form validation error not outputted in PyroCMS

Using PyroCMS 1.3.1 I've built a model that's pretty much a copy-paste version of the included contact model, but with a few tweaks. When all fields are inputted correctly everything works as expected. If a field is left out or incorrectly filled in, the form does not submit - just as expected.
However, I can't seem to get the form validation message to be outputted and this is driving me crazy. I'm sure I've just missed something very basic so if anyone could point it out I'd be grateful.
View file (form.php) contains this
<?php if (validation_errors()): ?>
<div class="error-box">
<?php echo validation_errors(); ?>
</div>
<?php elseif (isset($messages['error'])): ?>
<div class="error-box">
<p><?php echo $messages['error']; ?></p>
</div>
<?php endif; ?>
Controller (plugin.php) looks like this
class Plugin_mycustommodule extends Plugin {
private $rules = array(
array(
'field' => 'firstname',
'label' => 'lang:mycustommodule_firstname_label',
'rules' => 'required|trim|max_length[80]'
),
/* ... snip ... */
array(
'field' => 'license',
'label' => 'lang:mycustommodule_license_label',
'rules' => 'required'
)
);
public function __construct()
{
$this->lang->load('mycustommodule');
}
function form()
{
$this->load->library('form_validation');
$this->load->helper('form');
$this->form_validation->set_rules($this->rules);
// If the user has provided valid information
if ($this->form_validation->run())
{
/* ... Custom processing here ... */
// The try to send the email
if ($this->_send_email())
{
$message = $this->attribute('confirmation', lang('mycustommodule_sent_text'));
// Store this session to limit useage
$this->session->set_flashdata('success', $message);
redirect(current_url());
}
else
{
$message = $this->attribute('error', lang('mycustommodule_error_message'));
$data['messages']['error'] = $message;
}
}
// Set the values for the form inputs
foreach ($this->rules as $rule)
{
$form_values->{$rule['field']} = set_value($rule['field']);
}
$data['form_values'] = $form_values;
return $this->module_view('mycustommodule', 'form', $data, TRUE);
}
So it turns out that while I was working on customizing the CodeIgniters language files I must have messed up the upload of form_validation_lang.php because all entries was empty i.e. $lang['required'] = '';
So basically the validator looked for the error message, found an empty string, which was trimmed from being outputted. As suspected something silly, just not in the place I expected.
Let's hope this post will save someone else the trouble.

Resources